Children folders

Tony Jose Ponti's Avatar

Tony Jose Ponti

15 Jul, 2015 04:25 PM

Hello,
How can I make the following Velocity script for archiving display one level deeper. Currently, it provides me with a link the parent folder's index:
<a href="site://mysite/newsfolder/newsCfolder/2015folder/indexpage">2015</a>. But I'm looking for: <a href="site://mysite/newsfolder/newsCfolder/2015folder/07folder/indexpage">July</a>.

----structure----

+ formsfolder
- newsfolder
   + newsAfolder
   + newsBfolder
   - newsCfolder
      - 2015folder
                + 07folder (July)
                   index
         + 08folder (August)
       indexpage
+ reportsfolder

----script----

<br/><p><strong>Archives</strong>

       #set($parentFolder = $_.locatePage($currentPagePath).parentFolder)

        #set($folders = $parentFolder.children)
        #set($sortedFolders = $_SortTool.sort($folders, "name"))

        #foreach($folderItem in [1..$sortedFolders.size()])
            #set($arrayIndex = $sortedFolders.size() - $foreach.count)
            #if($sortedFolders[$arrayIndex].children)
                #set($folder = $sortedFolders[$arrayIndex])

               #set($folderLink = $_EscapeTool.xml($folder.link))
                | <a href="${folderLink}/index" title="$folder.metadata.title Archived TDI@Work Newletter">$folder.metadata.title</a>
            #end
        #end
  1. 1 Posted by Ryan Griffith on 15 Jul, 2015 08:43 PM

    Ryan Griffith's Avatar

    Hi Tony,

    You would need to add an additional #foreach within your existing #foreach that loops over the children of the current folder in the loop, or, what I would recommend, is create a macro that accepts a folder node and loops over it's children, while calling itself again. This way you can use recursion to handle traversing the nesting, rather than hardcoding nested #foreach loops which can be problematic and redundant.

    Also, I wanted to note that if you are running Cascade 7.10.1 or newer, you can replace the following line:

    #set($parentFolder = $_.locatePage($currentPagePath).parentFolder)
    

    with:

    #set($parentFolder = $currentPage.parentFolder)
    

    Please let me know if you have any questions.

    Thanks!

  2. 2 Posted by Tony Jose Ponti on 20 Jul, 2015 02:53 PM

    Tony Jose Ponti's Avatar

    Okay. Thank you.

  3. 3 Posted by Ryan Griffith on 20 Jul, 2015 03:35 PM

    Ryan Griffith's Avatar

    Not a problem at all, Tony, glad to hear I was able to help out.

    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 20 Jul, 2015 03:35 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