VELOCITY NEXT/PREVIOUS

bwmyers's Avatar

bwmyers

20 Apr, 2016 11:11 PM

Hello. I found another post that sort of does what I want. It is slightly different and I can't seem to get it to work.

Here is the post | http://help.hannonhill.com/discussions/velocity-formats/10642-is-us...

Attached is xml and velocity. Not sure what is going on. Doesn't seem to be pulling the any data in. Any help would be appreciated. Thanks!

  1. 1 Posted by Ryan Griffith on 21 Apr, 2016 01:30 PM

    Ryan Griffith's Avatar

    Hi Bradley,

    The Format provided in the other discussion was meant to be used for a Content Type Index Block, where the structure is:

    • system-index-block
      • system-page
      • ...
      • system-page

    In your case, you are using a Folder Index Block, so the XPath at the top of the Format will need to be adjusted. Specifically, system-index-block/system-page[@current] does not exist because the current page is nested under the /opportunity/statpack folder. Additionally, using system-index-block/system-page[not(@current)] will only give you non-current pages at the top level (i.e. base folder).

    Please let me know if you have any questions.

    Thanks!

  2. 2 Posted by bwmyers on 21 Apr, 2016 07:54 PM

    bwmyers's Avatar

    Ryan,

    Thanks for the feedback. Here is what I have come up with using the same xml minus calling page data. I took that out because I realized I could just check for current attribute w/o the calling page data.

    Included is the velocity and the output. For some reason the next & previous links aren’t populating off the .get(). But all other data is. Any help would be appreciated

    VELOCITY
    #set($getPages = $_XPathTool.selectNodes($contentRoot, '//system-page'))
    #set($counter=0)
    #set ( $articlesize = $getPages.size() )
    <ul>
    #foreach($page in $getPages)
        #set ($pageLink = $page.getChild("link").value)
        #if($page.getAttribute("current"))
            #set ($currentLink = $page.getChild("link").value)
            #set ($counter = $foreach.index)
            #set ($previous = $counter - 1)
            #set ($next = $counter + 1)
        #end

        #if($currentLink == $pageLink)
            #set ($prevPage = $page.get($previous).getChild("link").value)
            #set ($nextPage = $page.get($next).getChild("link").value)
            #set ($counter = $foreach.index)
        #end
    #end
    <li>SIZE: $articlesize | NEXT: $next | CURRENT: $counter | PREVIOUS: $previous | CURPG: $currentLink | PREVPG: $prevPage | NEXTPG $nextPage</li>
    </ul>

    OUTPUT
    <ul>
        <li>SIZE: 8 | NEXT: 4 | CURRENT: 3 | PREVIOUS: 2 | CURPG: site://BLIMPIE-FRANCHISING/opportunity/statpack/index | PREVPG: $prevPage | NEXTPG $nextPage</li>
    </ul>

  3. 3 Posted by Ryan Griffith on 21 Apr, 2016 08:16 PM

    Ryan Griffith's Avatar

    Hi Bradley,

    It looks like you are attempting to use get() on the page within the loop, not the entire array of pages. When you have a moment adjust your format as follows:

    #if($currentLink == $pageLink) 
            #set ($prevPage = $getPages.get($previous).getChild("link").value) 
            #set ($nextPage = $getPages.get($next).getChild("link").value) 
            #set ($counter = $foreach.index) 
        #end
    

    Please let me know if you have any questions.

    Thanks!

  4. 4 Posted by bwmyers on 21 Apr, 2016 09:31 PM

    bwmyers's Avatar

    Thanks Ryan. Looks good. Here is the final code in case anyone else comes along with the same issue:

    #set($getPages = $_XPathTool.selectNodes($contentRoot, '//system-page'))
    #set($counter=0)
    #set ( $articlesize = $getPages.size() )
    <ul>
        #foreach($page in $getPages)
            #set ($pageLink = $page.getChild("link").value)            
            ##<li>$pageLink</li>
            #if($page.getAttribute("current"))   
                #set ($currentLink = $page.getChild("link").value)
                #set ($counter = $foreach.index)
                #set ($previous = $counter - 1)
                #set ($next = $counter + 1)        
            #end
        
            #if($currentLink == $pageLink)
                #if($previous > -1)
                    #set ($prevPage = $getPages.get($previous).getChild("link").value)
                    <li><a href="${prevPage}" title="">« PREVIOUS</a></li>
                #else
                    #set ($prevPage = false)
                #end
                
                #if($next < $articlesize)
                    #set ($nextPage = $getPages.get($next).getChild("link").value)
                    <li><a href="${nextPage}" title="">NEXT »</a></li>
                #else
                    #set($nextPage = false)
                #end      
            #end
        #end
        ##<li>SIZE: $articlesize | NEXT: $next | CURRENT: $counter | PREVIOUS: $previous | CURPG: $currentLink | PREVPG: $prevPage | NEXTPG $nextPage</li>
    </ul>
    
  5. bwmyers closed this discussion on 21 Apr, 2016 09:31 PM.

Discussions are closed to public comments.
If you need help with Cascade CMS please start a new discussion.

Keyboard shortcuts

Generic

? 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

 

26 Aug, 2016 01:19 PM
25 Aug, 2016 03:02 PM
25 Aug, 2016 12:50 PM
24 Aug, 2016 08:43 PM
24 Aug, 2016 07:20 PM
21 Aug, 2016 01:20 PM