Tree Menu Mod

Author Message

David Jones

Thursday 19 October 2006 4:45:15 am

I'm using the tree menu to good effect (default template). Very useful.
However I wish to change the output slightly.

Currently this is what I have.

1.1
1.2
1.3
1.4

1.2 is clicked

1.1
1.2
   1.2.1
   1.2.2
1.3
1.4

1.2.1 is clicked

1.1
1.2
   1.2.1
      1.2.1.1
      1.2.1.2
   1.2.2
1.3
1.4

1.2.1.1 is clicked

1.1
1.2
   1.2.1
      1.2.1.1
          1.2.1.1.1
      1.2.1.2
   1.2.2
1.3
1.4

What I want to see at this stage is only the parent path, siblings, and children.

I want it to look like this:

1.2
   1.2.1
      1.2.1.1
         1.2.1.1.1
      1.2.1.2

can this be done?

Claudia Kosny

Thursday 19 October 2006 10:27:16 am

Hi David

First you need to specify exactly when the other menu entries should disappear. Is it once you reached the maximum depth or a depth of 4 or something else?
And why does the menu entry 1.2.1.2 appear here? It is neither a parent, a sibling or a child of 1.2.1.1.1.

1.2
  1.2.1
     1.2.1.1
        1.2.1.1.1
     1.2.1.2

Also please tell me the full name of the template you use (including the path starting with design)?

Greetings from Luxembourg

Claudia

David Jones

Friday 20 October 2006 12:45:48 am

Claudia

I want to display all parents / grand parents for the path to the selected page.
The pages siblings
the pages children

SO from the example above:

1.2
   1.2.1
      1.2.1.1 (selected)
          1.2.1.1.1
      1.2.1.2

I'm including this in the page layout template.

Thanks

Claudia Kosny

Friday 20 October 2006 2:01:11 am

Ah, out of some strange reasons I thought that 1.2.1.1.1 was selected - sorry.

Although you could use the treemnu for that you would have to do quite a ot of checking whether you want to display a certain item or not as the treemenu can be limited only in the depth, not in the width.

I think the easiest way would be to use the $module_result.path as this contains the names and urls of all parent nodes. Then you would need to fetch the siblings and the children.
So the result would be something like this (this is even a bit tested as I have done this for me a while ago):

{if is_set($module_result.node_id)}
 <ol>
 {foreach $module_result.path as $path_item}
  {if $path_item.url}
   <li><a class="parent" href={$path_item.url|ezurl()}>{$path_item.text|wash()}</a>
    <ol>
  {/if}
 {/foreach}
 
 {* now fetch the siblings and children of the current node *}
 {def $current_node = fetch('content', 'node', hash('node_id', $module_result.node_id))}
 {def $siblings = fetch('content', 'list', hash('parent_node_id', $current_node.parent_node_id,
                                                'sort_by', $current_node.parent.sort_array))}
 {foreach $siblings as $sibling}
  {* if the current node, fetch children *}
  {if $sibling.node_id|eq($current_node.node_id)}
   <li><a class="sibling" href={$sibling.url_alias|ezurl()}>{$sibling.name} </a>
   {def $children = fetch('content', 'list', hash('parent_node_id', $current_node.node_id,
                                                  'sort_by', $current_node.sort_array))}
   {if $children}
    <ol>
    {foreach $children as $child}
     <li><a class="child" href={$child.url_alias|ezurl()}>{$child.name} </a></li>
    {/foreach}
    </ol>
   {/if}
   </li>
  {else}
   <li><a class="sibling" href={$sibling.url_alias|ezurl()}>{$sibling.name} </a></li>
  {/if}
 {/foreach}
 </ol>
 
 {* we have opened count($module_result.path)|sub(1) li and ol which we need to close again *}
 {def $ol_cnt = count($module_result.path)|sub(1)}
 {for 1 to $ol_cnt as $cnt}
   </li>
  </ol>  
 {/for}
{/if}

Hope it helps

Claudia

David Jones

Friday 20 October 2006 3:48:51 am

THanks!

This is excellent.

I wonder, is it possible to skip the first 2 levels of the navigation.

so instead of outputting

1
   1.1
      1.1.1
         1.1.1.1

It outputs

1.1.1
     1.1.1.1

Claudia Kosny

Friday 20 October 2006 4:07:24 am

Just skip the first two iterations for where the module_result.path is looped through and remember that this changes the number of opened ol and li so you need to change the last loop as well. Not sure whether this will have the desired result but as the code is fairly easy just play with a bit to learn how it works.

Claudia

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.