Navigation Menu Top Level Folder

Aaron Smith's Avatar

Aaron Smith

16 Aug, 2016 05:22 PM

I inherited a Cascade site that uses a dynamically generated navigation menu with drop-downs. On the menu, the top level links are just used to activate the drop-down and the link is overridden. Unfortunately, because of how the dynamic nav menu is structured, if there are links in the drop-down that also contain child folders, the link is again overridden because the same code is generating link.

Is there a way to identify the top level of the folder structure, so I can use a conditional statement to only add the data-toggle at that level?

Here's the site:
https://dev.www.purdue.edu/caps/NEW_SITE/

And here's the code:
#set ($isFolder = ($asset.identifer.type == $_FieldTool.in("com.hannonhill.cascade.model.dom.identifier.EntityTypes").TYPE_FOLDER))

#if ($isFolder && $childCount == 1)
            <a href="$asset.link/index">$displayName</a>
        #elseif ($isFolder && $childCount > 1)
            <a href="$asset.link/index" class="dropdown-toggle" data-toggle="dropdown">$displayName<span class="caret"></span></a>
        #else
            <a href="$asset.link">$displayName</a>
        #end

  1. 1 Posted by Ryan Griffith on 16 Aug, 2016 07:09 PM

    Ryan Griffith's Avatar

    Hi Aaron,

    To confirm, do you just need to check if the folder is at the root level? If so, you could just check it's path to see if it contains a / or not. Top level folders would not contain a slash, while nested folders would. A couple of ways you could check:

    ## no '/' is present at all:
    $asset.path.indexOf("/") == -1
    
    ## size of "folder structure" is 1
    $asset.path.split("/").size() == 1
    

    Please let me know if you have any questions.

    Thanks!

  2. 2 Posted by Aaron Smith on 16 Aug, 2016 08:27 PM

    Aaron Smith's Avatar

    That did the trick! Thanks for your help!

  3. 3 Posted by Ryan Griffith on 17 Aug, 2016 02:26 PM

    Ryan Griffith's Avatar

    Not a problem at all, Aaron. I am glad to hear the proposed snippets worked 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 17 Aug, 2016 02:26 PM.

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

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