Information extraction
Information that is stored by eZ publish can be extracted using the "fetch" template operator. This operator gives access to the fetch functions that a module provides. It is typically used to extract nodes, objects, etc. using the content module. The fetch operator can only be used with modules that provide support for data fetching. Please refer to the "Fetch functions" section of the reference chapter for a complete overview of the fetch functions. The following model and table shows the usage and the parameters of the fetch operator.
fetch( <module>, <function>, <parameters> )
Parameter | Description |
---|---|
module |
The name of the target module. |
function |
The name of the fetch function within the target module. |
parameters |
An associative array containing the function parameters. |
A module's fetch functions and parameters are defined in the "function_definition.php" file within the directory of the module.
Fetching a single node
The following example demonstrates how the fetch operator can be used to extract a single node from the database.
{def $my_node=fetch( content, node, hash( node_id, 13 ) )} ... {undef}
The example above instructs eZ publish to fetch a single node from the content module. Only one parameter is given, which is the ID number of the node that should be fetched. The operator will return an "ezcontentobjecttreenode" object which will be stored in the $my_node variable. This variable can then be used to extract information about the node and the object that it encapsulates. For example, it is possible to extract the name, attributes and the time when the object was published. If the node is unavailable / non-existing or the currently logged in user doesn't have read access to it, the operator will return a FALSE boolean value.
Fetching multiple nodes
It is possible to fetch all the nodes that are directly below a specific node. This can be done by using list instead of node as the second parameter to the "fetch" operator. The following example demonstrates how the fetch operator can be used to extract all the nodes that are directly below node number 13.
{def $my_node=fetch( content, list, hash( parent_node_id, 13 ) )} ... {undef}
The operator will return an array of "ezcontentobjecttreenode" objects. The list fetch function of the content module can take several parameters. These parameters are optional and can be used to finetune the fetch for example by filtering out specific nodes. The following table gives an overview of the most commonly used parameters.
Parameter | Description |
---|---|
sort_by |
The method and direction that should be used when the nodes are sorted (must be specified as an array). |
limit |
The number of nodes that should be fetched. |
offset |
The offset at which the fetch should start. |
class_filter_type |
The type of filter that should be used, either "include" or "exclude". |
class_filter_array |
The type of nodes that should be included or excluded by the filter (must be specified as an array). |
The following example demonstrates how to fetch an alphabetically sorted array of the ten latest articles that are directly below node number 13.
{def $my_node=fetch( content, list, hash( parent_node_id, 13, limit, 10, class_filter_type, include, class_filter_array, array( 'article' ) ) )} ... {undef}
Please refer to the documentation page of the "list" fetch function for a complete overview of the available parameters and examples of usage.
Balazs Halasy (17/02/2005 10:52 am)
Balazs Halasy (17/06/2007 1:42 pm)
Comments
There are no comments.