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 Exponential 4.1. This enables you to fetch a node in a given language. | No. |
| remote_id | string | A new parameter since Exponential 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' )) Contributors
- Balazs Halasy Maintainer
- Ester Heylen Updated Maintainer
- Svitlana Shatokhina Maintainer
- Xavier Gouley (Smile) Commenter
- Markus Bader Commenter
- Peter Commenter
- Jan Commenter
Comments (4 historical)
Written by readers of the earlier documentation sites, kept as they were.
fetching the right language
Xavier Gouley (Smile) ·
Hi,
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
Markus Bader ·
It is possible to fetch several nodes by using an array(node_id_1, node_id_2, node_id_n) instead of an integer.
New optional parameter "language_code"
Peter ·
New in 4.1 but not yet documented:
{def $node_fr = fetch( 'content', 'node',
hash( 'node_id', 96,
'language_code', 'fre-FR'))}
Re: New optional parameter "language_code"
Jan ·
I have one trouble with new fetch.
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