Path

ez.no / ezpublish / documentation / customization / tips & tricks / creating tree menus


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

  1. Extension Treemenu (pubsvn)
  2. Operator treemenu (shipped with eZ)

 

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.)

Example

User is at the top category (home):

  • Folder 1
  • Folder 2
  • Folder 3
  • Folder 4

User is in Folder 2 (or subfolder 2):

  • Folder 1
  • Folder 2
  • Subfolder 1
  • Subfolder 2

Template code

{* 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.

But I also want to mark the active category and it's parent categories (making a trail)

Example

User is in Subfolder 2 of Folder 2:

  • Folder 1
  • # Folder 2
  • Subfolder 1
  • ## Subfolder 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).

Template code
{* 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

http://ez.no/ez_publish/documenta...ate_operators/miscellaneous/treemenu

This page contains information on a new system for treemenus in later versions of eZ (3.4 I think)

Contents

Customization

Access control
eZ publish API Documentation
Content structure
Custom design
Components
Tips & Tricks
    Debugging templates
    Javascript in templates
    Fetching current user
    Showing related objects
    Show which templates are used
    Fetching the ID of the parent
    One Article Folder
    Creating tree menus
    How can I use my own php script insid...
    Hiding attribute content
    Splitting an article over several pages
    Accessing section id in pagelayout
    List articles in folder
    Creating nice URLs
    Alt tag on images
    Improve the pagelayout.tpl
    Clean HTML tags
    Insert javascript call inside ezpub d...
    3rd party applications
    Fetch Function examples
    Display more than 15 items on your co...
    Including PHP files in templates
    Redirecting after content publishing
    HowTo see if article has an image
    Date and Time Formats
    Forms processing example: store user...
    Adjust Timezone
    Adding a Remove Button/Image
    Find the age in years for an object
    Editing, creating and removing conten...
    Indexing binary files with IFilters o...
Troubleshooting


Created

29/04/2003
10:43:16 am
by Niklas Gunnäs

Last updated

14/01/2004
12:06:25 am
by Björn Dieding@xrow.de

Authors

Niklas Gunnäs
Paul Wilson
Bård Farstad
Björn Dieding@xrow.de



This page is part of the eZ Publish documentation. The documentation is available under the GNU Free Documentation License. All contributions will be released under the terms of this license.