Expand my Community achievements bar.

CUrrent Page URL in Sling dynamic include

Avatar

Level 1

I am using the sling dynamic include for some of the resources, it's working in expected way. My question is can we get the current page url (/content/my-site/currentPage.html) in sling dynamically included component ?

Thanks in advance !!

3 Replies

Avatar

Level 9

Try using this:

${request.requestURL.toString}  --> the best way

or just composing it:

<sly data-sly-test.scheme="${request.scheme}"/>
    <sly data-sly-test.servername="${request.serverName}"/>
    <sly data-sly-test.serverport="${request.serverPort}"/>
    <sly data-sly-test.val="${request.requestURI}"/>
    ${scheme}://${servername}:${serverport}${val}

Not able to use slingRequest.getURL() in sightly

Avatar

Level 1

Thank you Hemant for your response.

We do not get the request URI in sling dynamic include, so .toString() is not working there.

Avatar

Level 6

In java for SlingHttpServletRequest request

final RequestPathInfo pathInfo = request.getRequestPathInfo();
final String resourcePath = pathInfo.getResourcePath();

or

final String resourcePath = request.getResource().getPath()