URLs

February 2, 2022

Working with URLs

All nodes have a url property:

<c:url value=${pageNode.url}" />
<c:url value=${fileNode.url}" />
<c:url value=${contentNode.url}" />

Like all JSTL tags, it is possible to assign a URL to a variable for future use within the script:

<c:url value="${node.url}" var="myUrl" />

A URL is generated from the combination of elements with <c:url />

${url.base}

  • Base URL (servlet/workspace/language)

${node.path}

  • Path of the node to be displayed

.view

  • Specifies the view to be applied (optional)

.html .xml .rss

  • Specifies the output type to be used

Examples:

<c:url value="${url.base}${node.path}.aView.html" />
<c:url value="${url.base}${node.path}.xml" />

The URL property of a content node contains the URL of the default view as html. An example of this is shown below, comparing two different ways of getting the same URL:

<c:url value="${currentNode.url}" />
<c:url value="${url.base}${node.path}.html" />

The first syntax is easier to use and is generally preferable.
The second syntax is often used when a different rendering mode, an alternative view, or an alternative output type is needed.

Different Rendering Modes

Access to different rendering modes for base and absolute URLs:

Base and Absolute:

${url.baseLive} and ${url.live}
${url.baseEdit}
and ${url.edit}
${url.basePreview}
and ${url.preview}
${url.baseContribute}
and ${url.contribute}

Base only:

${url.files}

Absolute only:

${url.studio}
${url.logout}

Adding ${url.server} as a prefix to a relative URL will make it absolute.

Example: Using a dynamically generated URL

Note the code snippet below. It leverages the JSTL core library required for generated the url of an image file:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:url value="/images/image.png” context="${url.currentModule}"/>

A URL is dynamically generated using context as the root path and value as the final location.