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

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 18 2025 22:27:21
Script start
Timing: Jan 18 2025 22:27:21
Module start 'layout'
Timing: Jan 18 2025 22:27:21
Module start 'content'
Timing: Jan 18 2025 22:27:21
Module end 'content'
Timing: Jan 18 2025 22:27:21
Script end

Main resources:

Total runtime0.0253 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0085 589.0469152.6250
Module start 'layout' 0.00850.0037 741.671939.4453
Module start 'content' 0.01210.0109 781.117289.3516
Module end 'content' 0.02300.0022 870.468834.3047
Script end 0.0252  904.7734 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.004015.9672140.0003
Check MTime0.00187.1887140.0001
Mysql Total
Database connection0.00135.045910.0013
Mysqli_queries0.003312.999830.0011
Looping result0.00000.058510.0000
Template Total0.00187.210.0018
Template load0.00103.980710.0010
Template processing0.00083.197610.0008
Override
Cache load0.00072.755110.0007
General
dbfile0.00031.214380.0000
String conversion0.00000.038740.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_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