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>»<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>»<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
|