Snippet: Template logic to display dynamic tertiary menu

Table of contents:

Created by Graham Brookins | Brookins Consulting

About

Initial posting of this example ....

This was created for a client who wanted a menu system that was 3 levels deep, server-side collapsable, current menu/document selected style. All I will say is that it works, fairly well. There are some static exceptions with variables you can change or remove the exceptions entirely.

I will post a cleaned up version of the source code with beter comments and less commented out code.

Template

{* ##################################################################################### *}
{* Level 1 : Top Level Node : Submenu List
{* ##################################################################################### *}
 
{* Exclude specials_node_id , static exception *}
{set specials_node_id=118}
 
{let submenu=fetch( content, list, hash( parent_node_id, $module_result.node_id, sort_by,array(array(priority, false() )) ) )
      parent=fetch('content','node', hash('node_id', $module_result.node_id) )
}
 
{* ##################################################################################### *}
 
 
{* ##################################################################################### *}
{* Level 3+ : Reverse Submenu List (Which we are not using now)
{* ##################################################################################### *}
{* These are good rules for reverse *}
{*
{section show=and($DesignKeys:used.parent_node|ne(2), $submenu|count|lt(1))}
 
{set submenu=fetch( content, list, hash( parent_node_id, $DesignKeys:used.parent_node, sort_by,array(array(priority, false() )
)  ))
     parent=fetch('content', 'node', hash('node_id', $module_result.content_info.parent_node_id) )
}
 
{/section}
*}
 
{* END: These are good rules for reverse *}
{* ##################################################################################### *}
 
 
 
{* ##################################################################################### *}
{* Level 3+ : Toplevel Attached Reverse Submenu List (works)
{* ##################################################################################### *}
 
{section show=and($DesignKeys:used.parent_node|ne(2), $module_result.content_info.node_depth|gt(2) )}
 
{*
Depth: {$module_result.content_info.node_depth}<br />
Key: {$DesignKeys:used.parent_node}
*}
 
{* must test each parent per depth or use other to only get top level parents | parent, is not enough, part of prob, *}
{set parent=fetch('content', 'node', hash('node_id', $module_result.content_info.parent_node_id)) }
 
{* same as parent, need testing to only get top level:
   {set submenu=fetch( content, list, hash( parent_node_id, $DesignKeys:used.parent_node )) }
*}
 
{set submenu=fetch( content, list, hash( parent_node_id, $DesignKeys:used.parent_node, sort_by,array(array(priority, false() )
)  )) }
 
{* ##################################################################################### *}
 {* test: if depth is gt(3), then, use depth as a manipulated placer into longer qry *}
  {section show=$module_result.content_info.node_depth|gt(3)}
   {set current_top_level_node_id=$module_result.path.1.node_id}
 
 
    {*
    <br />Depth gt(3), flag set
 
    {set submenu=fetch( content, list, hash( node_id, $current_top_level_node_id )) }
    {set parent=fetch( content, node, hash('node_id', $current_top_level_node_id )) }
    *}
 
    {set parent=fetch(content, node, hash( node_id, $current_top_level_node_id  ))}
    {set submenu=fetch( content, list, hash( parent_node_id, $current_top_level_node_id, sort_by,array(array(priority, false()
 ))   ))}
 
  {/section}
{/section}
{*
<br /><br />
 
{$module_result.path.1.node_id}
{$module_result.path|attribute(show,3)}
{$parent|attribute(show,3)}
*}
 
{*
{$module_result.content_info|attribute(show,3)}
<br />
{$DesignKeys:used|attribute(show,3)}
*}
 
{*
{$DesignKeys:used|attribute(show,2)}
 
{$DesignKeys:used|attribute(show,3)}
*}
 
{* ##################################################################################### *}
{* Level 1 - 2 : Submenu List
{* ##################################################################################### *}
 
{* Don't Show Submenu if on root page *}
{section show=$module_result.node_id|ne(2)}
 
{* Don't show menu if there are no submenu items *}
{section show=$submenu|count|gt(0)}
  <div id="sectheader" style="margin-top: 8px;"><span class="headerw">{$parent.name}</span></div>
 
  {section var=menu loop=$submenu}
 
  {* Exclude: Company: Specials Folder *}
  {section-exclude match=$menu.node_id|eq($specials_node_id)}
 
{*
  {set children=fetch( content, list, hash( parent_node_id, $menu.node_id, sort_by,array(array(priority, false() ))   ))}
  {section show=$children|count|lt(1)}
*}
 
   {switch name=selected match=$menu.node_id}
   {case match=$module_result.node_id}
    <div class="sectmain-match">
   {/case}
   {case}
    <div class="sectmain">
   {/case}
   {/switch}
 
   {switch name=selected match=$menu.node_id}
   {case match=$module_result.node_id}
    <a href={$menu.url_alias|ezroot} class="mainb-match">{$menu.name|shorten( 25 )}</a>
   {/case}
   {case}
    <a href={$menu.url_alias|ezroot} class="mainb">{$menu.name|shorten( 25 )}</a>
   {/case}
   {/switch}
  </div>
 
{* ##################################################################################### *}
{* 3rd Level : tertiary (separate) menus
{* ##################################################################################### *}
{* Don't Show Tertiary if on root page *}
 
 {* Exclude: Company: Specials Folder *}
  {section-exclude match=$menu.node_id|eq($specials_node_id)}
 
   {set parent=fetch(content, node, hash( node_id, $menu.node_id ))}
   {set tertiary=fetch( content, list, hash( parent_node_id, $menu.node_id, sort_by,array(array(priority, false() ))   ))}
 
{* Tertiary Menu  *}
{* Don't show menu if there are no tertiary items *}
{section show=$tertiary|count|gt(0)}
  {section var=tmenu loop=$tertiary}
  {section show=or($menu.node_id|eq($module_result.node_id), $tmenu.node_id|eq($module_result.node_id), and($tmenu.parent_node
_id|eq($menu.node_id), $tmenu.parent_node_id|eq($DesignKeys:used.parent_node))  )}
   {* Exclude: Company: Specials Folder *}
   {section-exclude match=$tmenu.node_id|eq($specials_node_id)}
   {switch name=selected match=$tmenu.node_id}
   {case match=$module_result.node_id}<div class="sectmain-child-match">{/case} {case}<div class="sectmain-child">{/case}
   {/switch}
    <a href={$tmenu.url_alias|ezroot} class="mainb-child" style="padding-left: 10px;">{$tmenu.name|shorten( 25 )}</a></div>
  {/section}
 
  {* End of sub-folder loop. *}
  {/section}
 
 
{* End of dont' show menu if no menus exist *}
{* /section *}
 
 
  {* End of sub-folder loop. *}
  {* /section *}
 
{* End of dont' show menu on root page *}
{/section}
 
  {* ##################################################################################### *}
  {/section}
 
  {* End of sub-folder loop. *}
  {/section}
 
{* End of dont' show menu if no menus exist *}
{/section}
 
{* End of dont' show menu on root page *}
{/section}
 
 
{/let}
 
 
{* ///////////////////////////////////////////////////////////////////// *}