Velocity version of following-sibling and preceding-sibling

MrFjords's Avatar


28 May, 2014 09:59 PM


I am trying to create two buttons on a page that link to the Previous and Next page in a of the current page in an index using velocity.

With XSLT I use to be able to do this using code like the following

<xsl:when test="@current='true'">
    <xsl:if test="following-sibling::system-folder[1]">
      <a class="toolnav" style="float:right;"><xsl:attribute name="href">[system-asset]<xsl:value-of select="following-sibling::system-folder[1]/path"/>/index[/system-asset]</xsl:attribute>Next</a>

    <xsl:if test="preceding-sibling::system-folder[1]">
      <a class="toolnav" style="float:right;"><xsl:attribute name="href">[system-asset]<xsl:value-of select="preceding-sibling::system-folder[1]/path"/>/index[/system-asset]</xsl:attribute>Previous</a>


Could someone point me in the right direction of how I could accomplish this using Velocity


  1. 1 Posted by Ryan Griffith on 29 May, 2014 12:14 PM

    Ryan Griffith's Avatar


    I believe you can accomplish this by setting a variable to the calling page and using the XPathTool to obtain the nodes.

    When you have a moment, give the following a try for starters and let me know how it works out:

    ## Get the calling page
    #set ($asset = $_XPathTool.selectSingleNode($contentRoot, "//system-page[@current]"))
    #set ($followingSibling = $_XPathTool.selectSingleNode($asset, "following-sibling::system-folder[1]"))
    #set ($precedingSibling = $_XPathTool.selectSingleNode($asset, "preceding-sibling::system-folder[1]"))
    #if ($followingSibling)
        <a class="toolnav" style="float:right;" href="[system-asset]${followingSibling.getChild("path").value}/index[/system-asset]">Next</a>
    #if ($precedingSibling)
        <a class="toolnav" style="float:right;" href="[system-asset]${precedingSibling.getChild("path").value}/index[/system-asset]">Previous</a>

    Please let me know if you have any questions.


  2. 2 Posted by MrFjords on 29 May, 2014 09:44 PM

    MrFjords's Avatar

    Thank you, I was able to get what I wanted to happen based on the code you posted.


  3. 3 Posted by Ryan Griffith on 30 May, 2014 12:10 PM

    Ryan Griffith's Avatar

    Not a problem at all, thank you for following up. I am glad to hear the Velocity snippet helped guide you to a solution.

    I'm going to go ahead and close this discussion, please feel free to comment or reply to re-open if you have any additional questions.

    Have a great day!

  4. Ryan Griffith closed this discussion on 30 May, 2014 12:10 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac