Forums / Install & configuration / Creating second menu

Creating second menu

Author Message

Patryk Kala

Tuesday 22 August 2006 2:14:08 am

{let menu1=fetch( 'content', 'list', hash(parent_node_id, NODE_ID,
sort_by, array( priority, true ),
class_filter_type, include, 
class_filter_array, array( 1 )))}
<ul>
{foreach $menu1 as $menuitem1}
<li>&rsaquo;&nbsp;</span><a href = "/{$menuitem1.url_alias}">{$menuitem1.name}</a></li>
        <div class="break"></div>
{/foreach}
</ul>
{/let}

I have this code, and how tu change it?
How to fetch subcategory?

Claudia Kosny

Tuesday 22 August 2006 9:35:16 am

Hello Patryk

If you want to create a menu, the treemenu operator comes in handy.
More information about this operator here:
http://ez.no/doc/ez_publish/technical_manual/3_8/reference/template_operators/miscellaneous/treemenu

Here an example for fetching subnodes with some comments regarding your code:
The general idea is to fetch all nodes on the main level and then to fetch the subnodes for each of the nodes on the main level. Theoretically you could do without the

- Please note that {let is deprecated and should be replaced by {def which I have done here.
- I replaced NODE_ID with $node._node_id which measn the the fetch function fetches all children of the current node. If you want to fetch the children of another node, just insert the id of this node.
- I replaced the argument '1' in the class_filter_array with 'folder'. This will do exactly the same as the class ids of the folder class is 1. But I find it easier to see what the fetch is actually supposed to be doing if I see the class identifiers instead of just the class id.
- I replaced your sort_array with the sort array of the nodes whose children we are fetching. Of course you can also use your own sort array.
- I have also declared a variable submenu. This variable will hold the result of the fetch for the subitems.

- You had wrong html in the foreach, e.g a closed span tag without opening the span first and a div where no divs are allowed. Therefore I removed most of it.
- If you want to link to a node, always use the operator ezurl() to create valid urls. Please note that that this operator adds the required double quotes around the link by default.

{def $mainmenu=fetch('content', 'list', hash(parent_node_id, $node.node_id,
                                                        sort_by, $node.sort_array,
                                                        class_filter_type, include, 
                                                        class_filter_array, array('folder')))
      $submenu=array()}

{if $mainmenu}
<ul>
 {foreach $mainmenu as $main_node}
  <li>&raquo;<a href={$main_node.url_alias|ezurl()}>{$main_node.name}</a>
   {* fetch subitems *}
   {set $submenu=fetch('content', 'list', hash(parent_node_id, $main_node.node_id,
                                                        sort_by, $main_node.sort_array,
                                                        class_filter_type, include, 
                                                        class_filter_array, array('folder')))}
   {if $submenu}
    <ul>
     {foreach $submenu as $sub_node}
       <li>&raquo;<a href={$sub_node.url_alias|ezurl()}>{$sub_node.name}</a></li>
     {/foreach}
    </ul>
   {/if}
  </li>
 {/foreach}
</ul>
{/if}

Most likely there are some typos in there, I did not try it out. I would also strongly suggest to have a look at the templates that are shipped with EZ, change the code there and check what happens. This way you will learn most about using the template language.

Greetings from Luxembourg

Claudia

eZ debug

Timing: Jan 18 2025 19:17:04
Script start
Timing: Jan 18 2025 19:17:04
Module start 'content'
Timing: Jan 18 2025 19:17:04
Module end 'content'
Timing: Jan 18 2025 19:17:04
Script end

Main resources:

Total runtime0.1933 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.0069 587.7109180.8359
Module start 'content' 0.00690.0057 768.546993.8984
Module end 'content' 0.01260.1806 862.4453522.2813
Script end 0.1932  1,384.7266 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00402.0801200.0002
Check MTime0.00170.8898200.0001
Mysql Total
Database connection0.00130.694910.0013
Mysqli_queries0.142773.85181410.0010
Looping result0.00160.81691390.0000
Template Total0.180293.210.1802
Template load0.00110.570210.0011
Template processing0.179192.645610.1791
Override
Cache load0.00080.394310.0008
Sytem overhead
Fetch class attribute can translate value0.00351.785610.0035
XML
Image XML parsing0.00030.157310.0003
General
dbfile0.00251.2699200.0001
String conversion0.00000.003130.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