createLinkTo
Purpose
Creates a link that can be used where necessary (for example in an href, javascript, ajax call etc.)Examples
Example controller for an application called "shop":Example usages for the "shop" app:<g:createLinkTo dir="css" file="main.css" /> == /shop/css/main.css
Example as a method call in GSP only:<link type="text/css" href="${createLinkTo(dir:'css',file:'main.css')}" /> Results in:<link type="text/css" href="/shop/css/main.css" />
Description
Attributes
dir (optional) - the name of the directory within the grails app to link to
file (optional) - the name of the file within the grails app to link to
Source
Show Source
def createLinkTo = { attrs ->
def writer = out
if (attrs.base) {
writer << attrs.remove('base')
} else {
handleAbsolute(attrs)
}
writer << grailsAttributes.getApplicationUri(request);
if(attrs['dir'] ) {
writer << "/${attrs['dir']}";
}
if(attrs['file']) {
writer << "/${attrs['file']}"
}
}