Forums / Developer / Tree Menu Mod

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

eZ debug

Timing: Jan 19 2025 00:09:17
Script start
Timing: Jan 19 2025 00:09:17
Module start 'content'
Timing: Jan 19 2025 00:09:17
Module end 'content'
Timing: Jan 19 2025 00:09:17
Script end

Main resources:

Total runtime0.1620 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0066 587.5391180.8516
Module start 'content' 0.00660.0047 768.390697.8281
Module end 'content' 0.01130.1506 866.2188526.9609
Script end 0.1619  1,393.1797 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00372.3130200.0002
Check MTime0.00140.8647200.0001
Mysql Total
Database connection0.00080.500510.0008
Mysqli_queries0.113169.82261410.0008
Looping result0.00160.98641390.0000
Template Total0.150292.710.1502
Template load0.00080.512310.0008
Template processing0.149492.208510.1494
Override
Cache load0.00060.355610.0006
Sytem overhead
Fetch class attribute can translate value0.00171.077910.0017
XML
Image XML parsing0.00060.374610.0006
General
dbfile0.00402.4824200.0002
String conversion0.00000.003530.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs