Forums / Developer / Get the main parent node_id on a simplified tree menu

Get the main parent node_id on a simplified tree menu

Author Message

Lo' F.

Friday 24 September 2010 5:17:59 am

Hi guys,

Here's the tree structure:

"

- main parent (frontpage)

--------- folder

------------------- document page 1

------------------- document page 2

"

The folder is embedded in the parent frontpage as an itemize_sub_item and so it is shown with its children under it. Those children are links to their relative document pages which layout have a simplified tree menu on their left.

What I need is to get the main parent (frontpage) node_id from the show_simplified_menu.tpl.

$contentStructureTree.parent_node.node.node_id returns the node_id of the document pages' folder.

How can I get the upper one?

Many, many thanks!

loredanaebook.it

Nathan Kelly

Monday 27 September 2010 11:03:12 pm

First you need to know the depth of the main parent node, then use $node.path_array to find that node ID. e.g. if the main parent node depth is 1 then use $node.path_array.1, this will return the node ID for the main parent.
Use {$node.path_array|attribute(show)} from one of your document nodes and you'll see something like this:
Attribute Type Value
0 integer 1
1 integer 2
2 integer 85
3 integer 80
4 integer 90
This is a fairly common practice for tree menus, sometimes you might have to use $module_result.path.1.node_id instead, this will depend on the context you are in, you might be in the pagelayout.tpl for example.
The method you are using can also work but to get the main parent you need to go up another level, i.e. $contentStructureTree.parent.parent.node_id but I'd suggest you use the path_array method because it doesn't have to fetch as many objects to get the same result.

Hope that helps.

Cheers
Nathan.

Pardon me while I burst into flames...

Lo' F.

Tuesday 28 September 2010 9:14:09 am

Nathan, thank you so much! Your explanation has really helped me having a much clearer vision of the things now.

From the simplified_treemenu/show_simplified_treemenu.tpl template, though having some trouble getting something out using path_array and since path_string seems to return instead the parent node I was looking for, I made it work this way..

{if $contentStructureTree.parent_node.node.path_string|contains("284")}..

I am a little in rush to have this working in a way or another, so for the time being, it gonna be alright.

But definitely I will look into this stuff again!

Thank you again!

loredanaebook.it

Nathan Kelly

Tuesday 28 September 2010 5:45:18 pm

No problem Lo, glad I have helped in some way.

Because I don't have an install running that uses the simplified tree menu template I can't quickly test this, if you can't access the path_array you should try dumping the variables with: {$contentStructureTree.parent_node.node|attribute(show)}

This will show you all of the available information of the node. If ever in doubt you should try dumping variables this way, it's usually the quickest way to find what you need.

Cheers
Nathan.

Pardon me while I burst into flames...

eZ debug

Timing: Jan 29 2025 23:48:35
Script start
Timing: Jan 29 2025 23:48:35
Module start 'content'
Timing: Jan 29 2025 23:48:35
Module end 'content'
Timing: Jan 29 2025 23:48:35
Script end

Main resources:

Total runtime0.1227 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.0058 588.0781180.8203
Module start 'content' 0.00580.0072 768.898498.5859
Module end 'content' 0.01300.1096 867.4844526.8594
Script end 0.1226  1,394.3438 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00352.8525200.0002
Check MTime0.00151.1893200.0001
Mysql Total
Database connection0.00070.573010.0007
Mysqli_queries0.080165.32111410.0006
Looping result0.00100.81921390.0000
Template Total0.109389.110.1093
Template load0.00090.732910.0009
Template processing0.108488.365910.1084
Override
Cache load0.00060.494710.0006
Sytem overhead
Fetch class attribute can translate value0.00060.520910.0006
XML
Image XML parsing0.00030.213410.0003
General
dbfile0.00514.1893200.0003
String conversion0.00000.004930.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