node
Summary
Fetches a node (identified by either an ID number or a path).Usage
fetch( 'content', 'node', hash( [ 'node_id', node_id, ] [ 'node_path', node_path, ] [ 'language_code', language_code, ] [ 'remote_id', remote_id ] ) )
Parameters
Name | Type | Description | Required |
---|---|---|---|
node_id | integer | The ID number of the node that should be fetched. | No. |
node_path | string | The path of the node that should be fetched. | No. |
language_code | string | A new parameter since eZ Publish 4.1. This enables you to fetch a node in a given language. | No. |
remote_id | string | A new parameter since eZ Publish 4.1. This enables you to fetch a node by its remote ID number. | No. |
Returns
An ezcontentobjecttreenode object of FALSE.
Description
This function fetches a single node and returns it as a ezcontentobjecttreenode. The target node must be specified using either the "node_id" or the "node_path" parameter. If no node can be found, or if an error occurs, the function will return FALSE.
Examples
Example 1
{def $my_node=fetch( 'content', 'node', hash( 'node_id', 96 ) )} {$my_node.name|wash}
Fetches node number 96 and outputs the name of the object that is encapsulated by that node.
Example 2
{def $my_node=fetch( 'content', 'node', hash( 'node_path', 'news/article_test' ) )} {$my_node.name|wash}
Fetches the node by the specified path and outputs the name of the object that is encapsulated by that node.
Example 3
{def $my_node=fetch( 'content', 'node', hash( 'node_path', 'news/article_test' ) )} Views: {$my_node.view_count}
Fetches the node by the specified path and outputs the number of times this node has been viewed. (The "updateviewcount.php" cronjob must be run periodically.)
Example 4
fetch('content', 'node', hash('node_id', 66, 'language_code', 'pol-PL'))
This parameter is especially useful when you need to grab content or a URL in a different language than the one users are viewing a siteaccess in.
Example 5
fetch('content', 'node', hash('remote_id', '1b26c0454b09bb49dfb1b9190ffd67cb' ))
Balazs Halasy (06/02/2004 12:08 pm)
Ester Heylen (18/11/2009 5:10 pm)
Comments
fetching the right language
Wednesday 07 June 2006 9:49:11 am
Xavier Gouley (Smile)
Default language code is english ;
My language code is "fre-FR" (only for my siteaccess front-office) ;
I'm in the pagelayout.tpl, for the french siteaccess ;
I fetches the current node (instead of $node that is not defined in the pagelayout) to $currentNode ;
Now, if I write : $currentNode.object|attribute, I retrieves the fre-FR version,
BUT if I write $currentNode.object.data_map|attribute, I retrieves the english version...
Finally, I can't have the french version of an attribute !
Is it a bug (ez 3.8) ?
Fetching several nodes
Friday 11 July 2008 7:47:52 am
Markus Bader
New optional parameter "language_code"
Wednesday 24 June 2009 4:33:39 pm
Peter
{def $node_fr = fetch( 'content', 'node',
hash( 'node_id', 96,
'language_code', 'fre-FR'))}
Re: New optional parameter "language_code"
Friday 11 September 2009 2:53:26 pm
Jan
Current locale is french, trying to fetch it with:
{def $node_fr = fetch( 'content', 'node',
hash( 'node_id', 96,
'language_code', 'eng-US'))}
Content i've got in english, but url_alias of the $node_fr is in french ... How can i get url_alias in english ?
Thanks