Skip to content

Instantly share code, notes, and snippets.

@cfalzone
Created October 30, 2015 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cfalzone/6282bcb4d0aff6ec0a98 to your computer and use it in GitHub Desktop.
Save cfalzone/6282bcb4d0aff6ec0a98 to your computer and use it in GitHub Desktop.
dotCMS Flat Navigation Example (not tested)
## Define a macro to handle the children
#macro(navFlatChildren $nav_children, $level)
#foreach($nav_item in $nav_list)
#if(!$nav_item.folder && $UtilMethods.isSet($nav_item.href))
## so we are not a folder and we have a url so show a link
<li><a href="${nav_item.href}">$nav_item.title</a></li>
#else
#if($nav_item.folder
&& $nav_item.children
&& $nav_item.children.size() > 0
&& $levels_deep > $level)
## Now we have a folder with children so show it's children
#navFlatChildren($nav_item.children, $math.add(level,1))
#end
#end
#end
#end
## Pull the top level nav items
#set($nav_list = $navtool.getNav("/"))
## You are going to want to set some sort of limit of how deep to go
#set($levels_deep = 5)
## You might also consider using #dotCache around this whole chunck,
## it has the potential to be a heaver chunck of code.
<ul>
#foreach($nav_item in $nav_list)
#if(!$nav_item.folder && $UtilMethods.isSet($nav_item.href))
## so we are not a folder and we have a url so show a link
<li><a href="${nav_item.href}">$nav_item.title</a></li>
#else
#if($nav_item.folder
&& $nav_item.children
&& $nav_item.children.size() > 0
&& $levels_deep > 1)
## Now we have a folder with children so show it's children
#navFlatChildren($nav_item.children, 2)
#end
#end
#end
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment