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

eZ debug

Timing: Jan 31 2025 06:16:40
Script start
Timing: Jan 31 2025 06:16:40
Module start 'layout'
Timing: Jan 31 2025 06:16:40
Module start 'content'
Timing: Jan 31 2025 06:16:41
Module end 'content'
Timing: Jan 31 2025 06:16:41
Script end

Main resources:

Total runtime1.1597 sec
Peak memory usage4,096.0000 KB
Database Queries62

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0040 588.0313151.1953
Module start 'layout' 0.00400.0021 739.226636.6172
Module start 'content' 0.00621.1526 775.8438995.8594
Module end 'content' 1.15880.0009 1,771.703111.8750
Script end 1.1597  1,783.5781 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00290.2523160.0002
Check MTime0.00130.1087160.0001
Mysql Total
Database connection0.00070.063510.0007
Mysqli_queries1.098194.6868620.0177
Looping result0.00050.0434600.0000
Template Total1.127597.220.5638
Template load0.00200.171220.0010
Template processing1.125597.053220.5628
Template load and register function0.00130.108110.0013
states
state_id_array0.00170.144910.0017
state_identifier_array0.00080.071420.0004
Override
Cache load0.00170.1503590.0000
Sytem overhead
Fetch class attribute can translate value0.00060.048030.0002
Fetch class attribute name0.00190.161760.0003
XML
Image XML parsing0.00270.235930.0009
class_abstraction
Instantiating content class attribute0.00000.001260.0000
General
dbfile0.00380.3246250.0002
String conversion0.00000.000540.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
10content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
6content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 24
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs