I wish to get the current url minus the file name that is being currently referenced. Whether the solution is in JSP or CQ5 doesn’t matter. However, I am trying to use the latter more to get used to it.
I’m using this documentation but it’s not helping. CQ5 Docs.
The example I found retrieves the full current path, but I don’t know how to strip the file name from it:
<% Page containingPage = pageManager.getContainingPage(resourceResolver.getResource(currentNode.getPath()));
%>
<a href="<%=containingPage.getPath() %>.html">Profile</a>
I don’t know anything about CQ5, but since
getPath()returns an ordinary Java string I expect you could just take the prefix up to the last slash, which for a stringscan be done withs.substring(0, s.lastIndexOf('/')+1). If you have to make it into a one-liner, you could docontainingPage.getPath().substring(0, containingPage.getPath().lastIndexOf('/')+1).