Call node id from within template

Author Message

paul bolger

Wednesday 22 April 2009 6:13:39 pm

This is probably really obvious, but how do you call a particular node (by node_id) from within a template? I know you could do a fetch, but is there a way of just saying "get node 2" for example.

Paul Bolger

Carlos Revillo

Thursday 23 April 2009 12:27:41 am

take a look at the fetch functions. you can do a lot with them. for your case just try

    {def $my_node = fetch( "content", "node", hash( "node_id", 2 ) )}

Regards.

paul bolger

Thursday 23 April 2009 1:11:24 pm

Thanks Carlos

I was wondering whether there was a built in function - like $children - with less processing overhead.

Paul Bolger

André R.

Thursday 23 April 2009 2:33:39 pm

And with $children, you mean $node.children?

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

paul bolger

Friday 24 April 2009 6:27:55 pm

$node.children, sorry...

Paul Bolger

André R.

Saturday 25 April 2009 11:16:19 am

But you need to get $node from somewhere to be able to call it, so basically you need to fetch it.
The fetches are only as complex / heawy as you let them (ref list or tree fetch with lots of filters), the only baseline overhead is that the abstraction causes some 3-6 php functions to be called internally to do the fetch.
If you want to lower that then you can create a template function where you do the fetch directly against db or ezp php api(eZContentObjectTreeNode::fetch).

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

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 19 2025 00:54:34
Script start
Timing: Jan 19 2025 00:54:34
Module start 'layout'
Timing: Jan 19 2025 00:54:34
Module start 'content'
Timing: Jan 19 2025 00:54:35
Module end 'content'
Timing: Jan 19 2025 00:54:35
Script end

Main resources:

Total runtime0.8500 sec
Peak memory usage4,096.0000 KB
Database Queries68

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0057 589.2813152.6406
Module start 'layout' 0.00570.0042 741.921939.4766
Module start 'content' 0.00990.8384 781.3984608.7813
Module end 'content' 0.84830.0017 1,390.179716.1406
Script end 0.8499  1,406.3203 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00340.3948160.0002
Check MTime0.00160.1857160.0001
Mysql Total
Database connection0.00090.105110.0009
Mysqli_queries0.779091.6496680.0115
Looping result0.00070.0776660.0000
Template Total0.805694.820.4028
Template load0.00220.256120.0011
Template processing0.803494.526620.4017
Template load and register function0.00020.020910.0002
states
state_id_array0.00150.173510.0015
state_identifier_array0.00140.167420.0007
Override
Cache load0.00180.2176250.0001
Sytem overhead
Fetch class attribute can translate value0.00150.172330.0005
Fetch class attribute name0.00100.113480.0001
XML
Image XML parsing0.00740.865930.0025
class_abstraction
Instantiating content class attribute0.00000.0029110.0000
General
dbfile0.00921.0864230.0004
String conversion0.00000.001340.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
5content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
6content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
7content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 23
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs