Forums / Developer / Tree Menu Mod / Comment47162

Author Topic

Claudia Kosny

Friday 20 October 2006 2:01:11 am

Comment47162

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