Caution: This documentation is for eZ Publish legacy, from version 3.x to 6.x.
For 5.x documentation covering Platform see eZ Documentation Center, for difference between legacy and Platform see 5.x Architecture overview.

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

NameTypeDescriptionRequired
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)

Balazs Halasy, Svitlana Shatokhina, Ester Heylen


Comments

  • fetching the right language

    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

    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"

    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"

      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