Forums / Install & configuration / Call node id from within template

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