"Dynamic" left menu

Author Message

Krischan Hauschkez

Thursday 09 November 2006 11:09:25 am

Hi!

I need a little help...

I made up a site using a top and a left menu. In the left one there is only one menu level shown. Now I want the next level been shown, too. But only, when I click on the "mother" node. This is how it is now:

1 News
2 Contact
3 Links
4 Things

And when I click on 3, it should be like this:

1 News
2 Contact
3 Links
- Good Links
- Bad Links
- Other Links
4 Things

How could I do that?

TIA!

Jacobo Quiles

Monday 13 November 2006 12:59:36 am

Hi,

You could try something like this:

{def $second_level_children=array()}
{def $root_node_children=fetch('content', 'list', hash('parent_node_id', 2))}

{if gt($root_node_children|count,0)}
<ul>
{foreach $root_node_children as $child}
<li>
<a href={$child.url_alias|ezurl()}>{$child.name|wash()}</a>
{if or(eq($child.node_id,$module_result.node_id),eq($module_result.path.1,$child.node_id))}
{set $second_level_children=fetch('content','list',hash('parent_node_id', $child.node_id))}
{if gt($second_level_children|count,0)}
<ul>
{foreach $second_level_children as $child2}
<li><a href={$child2.url_alias|ezurl()}>{$child2.name|wash()}</a></li>
{/foreach}
</ul>
{/if}
{/if}
<li>
{/foreach}
</ul>
{/if}

First fetch the elements of the top level, foreach element check if it's the node that is being viewed or if it's one of its children's node. If so, show its children.

The code above has not been tested, but maybe would give you an idea on how to do it.

Microblau SL
http://www.microblau.net

Krischan Hauschkez

Monday 13 November 2006 1:03:21 pm

Excellent work, Jacobo, really excellent! Thank you very, very much! I have to modify it a bit, but your code works at it is!

Thankful greetings,
Krischan

kracker (the)

Monday 13 November 2006 1:36:04 pm

I have documented this conversation's question, answer and source code in the <i>eZpedia</i>, <b>eZ publish community documentation</b>

<i>http://pubsvn.ez.no/wiki/en/ez/solution_dynamic_left_menu</i>

Please feel free to update the entry to include the actual tested sourced you used as a solution so all may do so as well ...

Cheers,
//kracker
<i>Modest Mouse - 3rd Planet (radio-edit)</i>

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

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