Search in the Documentation:

Managing URLs in scripts

It is possible to access the default HTML URL from any node using the getUrl method of the JCRNodeWrapper class. For example we can use the expression ${currentNode.url} to retrieve the URL of the current node including the current web application context. URL must then always be output using the <c:url/> tag to make sure that context, encoding, URL rewriting and session tracking will work properly.

URLs may therefore be generated as in the example below (be careful as the getUrl returns an URL that includes the web application context, you must pass a “/” to the c:url tag to make sure it does not include it twice):

<c:url var=”nodeUrl” value=”${currentNode.url}” context=”/”/>
<a href=”${nodeUrl}”/>

If you need to add more parameters to the URL, you can do so as in the following example:

<c:url var=”nodeUrl” value=”${currentNode.url}” context=”/”>
<c:param var=”param1” value=”value1”/>
</c:url>

URL building
The getUrl() method allows to quickly retrieve the URL for a node, but however in order to have more control over the generation (mode, workspace, view, template type), it might be sometimes necessary to build the URL manually.

A URL is composed of the following elements:

/context/mode/workspace/lang/nodePath.view.templateType

You may rely on the JSTL tag c:url to provide the web application context.

When rendering content, the BaseAttributesFilter inserts into the request a bean named “url” and of type org.jahia.services.render.URLGenerator. It is then possible to use this bean to access various system pre-defined URLs. For example :
${url.base }

Returns the current mode and workspace in the current language (ex: /cms/render/default/en).

Other shortcuts to retrieve other modes exist. For example ${url.baseEdit} will be used to retrieve the URL to the Edit mode on the default workspace in the current language.

The building of an URL is therefore achieved by adding the node’s path, its view and the desired template type to one of the base URLs. We now present some example of different node URLs.
For the default view:

${url.base}${currentNode.path}.html

For a view called “big”:

${url.base}${currentNode.path}.big.html

For a “txt” template type:

${url.base}${currentNode.path}.txt

Combined with the <c:url/> tag this becomes:

<c:url var=”myUrl” value=”${url.base}${currentNode.path}.txt”/>
<a href=”${myUrl}”/>

The URLGenerator provides shorts to different modes for the current resource (ie the node currently being rendered). For example : ${url.live} actually expands to ${url.baseLive}${renderContext.mainResource.path}. The same is true for the preview, edit, contribute and studio modes. It also contains shortcut to the some of the various Jahia servlets, as in the examples below:
${url.find} points to Jahia’s find servlet /cms/find (used to perform AJAX searches)
${url.files} points to Jahia’s file servlet /cms/files
An URL to a file would then look like this:

<c:url value='${url.files}${fileNode.path}' value=”fileUrl”/>
<a href=”${fileUrl”/>

References module local content
To retrieve the URL to an resource provided by a module, a getCurrentModule() accessor method is provided on the URLGenerator class. So you can reference an image in the current module, you can do something similar to the example below:

<c:url var=”myImage” value=”${url.getCurrentModule}/img/image.png”/>
<img scr=”${myImage}”/>