ez.no / ezpublish / documentation / customization / tips & tricks / creating tree menus
These documentation pages are no longer maintained. Please visit the new documentation site.
This information is valid, but there are other resources that you should use for creating tree menus
Works on: eZ publish v3.0
You want a menu to show the subitems of a parent item if we are at that parent item. (Look further below if you want a "trail" of the items.)
User is at the top category (home):
User is in Folder 2 (or subfolder 2):
{* Set your top category here *} {let top_cat=2 used_node=false()} {* See if we have already a node id otherwise use the top category as current node *} {section show=is_set($DesignKeys:used.node)} {set used_node=$DesignKeys:used.node} {section-else} {set used_node=$top_cat} {/section} {* Get a proper node object *} {let node_obj=fetch(content,node,hash(node_id,$used_node))} {* FIRST LEVEL *} {section loop=fetch(content,list,hash(parent_node_id,$top_cat, class_filter_type, "include", class_filter_array, array(1),sort_by,array(array(priority))))} - <a class="path" href={concat("/content/view/full/",$:item.node_id,"/")|ezurl}>{$:item.name}</a><br /> {* SECOND LEVEL *} {section show=$node_obj.path_array|contains($:item.node_id) loop=fetch(content,list,hash(parent_node_id,$:item.node_id, class_filter_type, "include", class_filter_array, array(1),sort_by,array(array(priority))))} -- <a class="path" href={concat("/content/view/full/",$:item.node_id,"/")|ezurl}>{$:item.name}</a><br /> {* THIRD LEVEL *} {section show=$node_obj.path_array|contains($:item.node_id) loop=fetch(content,list,hash(parent_node_id,$:item.node_id, class_filter_type, "include", class_filter_array, array(1),sort_by,array(array(priority))))} --- <a class="path" href={concat("/content/view/full/",$:item.node_id,"/")|ezurl}>{$:item.name}</a><br /> {* FOURTH LEVEL *} {section show=$node_obj.path_array|contains($:item.node_id) loop=fetch(content,list,hash(parent_node_id,$:item.node_id, class_filter_type, "include", class_filter_array, array(1),sort_by,array(array(priority))))} ---- <a class="path" href={concat("/content/view/full/",$:item.node_id,"/")|ezurl}>{$:item.name}</a><br /> {/section} {/section} {/section} {/section} {/let} {/let}
You can change the fetch functions used if you want different types of items to show in your menu or if you want them sorted in a different way (see FetchFunction). The above example only shows categories (class id: 1) and sorts them by priority.
User is in Subfolder 2 of Folder 2:
To achieve this, use the following template code with the menu item (obviously you can/should replace the "#" with something else to make it look nicer).
{* Show trail or active menu *} {section show=eq($:item.node_id,$used_node)} ## {section-else} {section show=$node_obj.path_array|contains($:item.node_id)} # {/section} {/section}
This code should be placed after the section loop or section show and before the href line in each level of the menu script.
IE. (note this is only a small section of combined script for example purpose)
<PRE>{* FIRST LEVEL *} {section loop=fetch(content,list,hash(parent_node_id,$top_cat, class_filter_type, "include", class_filter_array, array(1),sort_by,array(array(priority))))} {section show=eq($:item.node_id,$used_node)} ## {section-else} {section show=$node_obj.path_array|contains($:item.node_id)} # {/section} {/section} <a class="topmenu" href={concat("/content/view/full/",$:item.node_id,"/")|ezurl}>{$:item.name}</a><br /></PRE>
Comments
New version
Mark Marsiglio
Monday 18 October 2004 4:53:08 am
This page contains information on a new system for treemenus in later versions of eZ (3.4 I think)