Korneel Staelens wrote:

> Im trying to use Twitter Cards when sharing content from my site. Therefore I 
> need to give the absolute URL of an image in a Metatag.
> I can get the absolute URL by using 
> ${damfn.getAssetLink(content.blogImage)}
> 
> By this, i get /dam/... 
> 
> How can I get this to be a absolute link?) 
> 
> (i.e. http://localhost:8080/dam/...)

I don't know if Mangolia has any utilities for this, but we created our utility 
function for external links which gets the scheme, server name and server port 
from the HttpServletRequest via MgnlContext:

----
public String makeExternalLink(String link) {
    if (LinkUtil.isExternalLinkOrAnchor(link)) {
        return link;
    } else {
        if (!link.startsWith("/")) {
            link = "/" + link;
        }
        return getExternalPrefix() + link;
    }
}

private String getExternalPrefix() {
    HttpServletRequest request = MgnlContext.getWebContext().getRequest();
    String scheme = request.getScheme();
    String prefix = request.getScheme() + "://" + request.getServerName();
    int port = request.getServerPort();
    if (!((scheme.equalsIgnoreCase("http") && port == 80) || 
(scheme.equalsIgnoreCase("https") && port == 443))) {
        prefix = prefix + ":" + port;
    }
    return prefix;
}
----

Nils.

----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------

Reply via email to