Skip to the content
Documentation

Information extraction

No ratings yet

Templates read data with fetch. The operator calls a fetch function of a module, for example list of the content module, with its parameters as a hash, and returns the result:

fetch( '<module>', '<function>', hash( '<parameter>', <value>, ... ) )

Each module defines its fetch functions in its function_​definition.​php; extensions add their own. Fetch functions check the permissions of the current user: a node the user may not read is not returned. Every fetch function of the installation, with its parameters and defaults, is listed in Fetch functions; those of the content module in content.

One node

{def $about = fetch( 'content', 'node', hash( 'node_id', 13 ) )}
{if $about}
    <a href={$about.url_alias|ezurl}>{$about.name|wash}</a>
{/if}
{undef $about}

The result is a node (eZContentObjectTreeNode), or false when the node does not exist or the user may not read it, so test it before you use it.

The children of a node

list returns the nodes directly below a parent; tree goes deeper. Both take the same parameters for sorting, limiting and filtering:

{def $articles = fetch( 'content', 'list',
                        hash( 'parent_node_id',     $node.node_id,
                              'class_filter_type',  'include',
                              'class_filter_array', array( 'article' ),
                              'sort_by',            array( 'published', false() ),
                              'limit',              10 ) )}
{foreach $articles as $article}
    {node_view_gui content_node=$article view='line'}
{/foreach}
{undef $articles}
Parameter Does
parent_node_id The parent node. Required.
sort_by An array of field and direction, true() for ascending: array( 'published', false() ) is newest first. $node.sort_array is the sorting the editors chose for the parent.
limit, offset How many nodes, and from which position.
class_filter_type, class_filter_array 'include' or 'exclude', and the class identifiers.
attribute_filter Conditions on attributes, such as array( array( 'published', '>', $since ) ).
depth How deep a tree fetch goes.
load_data_map true() reads the content attributes of every node in one go, when the template prints them.

Every parameter, with its default: content/list and content/tree.

Paging

list_count takes the same filters and returns the number of nodes; with the offset from the view parameters and the standard navigator template it makes a paged list:

{def $page_limit = 10
     $filter = hash( 'parent_node_id', $node.node_id )
     $count = fetch( 'content', 'list_count', $filter )
     $children = fetch( 'content', 'list', $filter|merge( hash( 'offset', $view_parameters.offset,
                                                                 'limit', $page_limit,
                                                                 'sort_by', $node.sort_array ) ) )}
{foreach $children as $child}
    {node_view_gui content_node=$child view='line'}
{/foreach}
{include name=navigator
         uri='design:navigator/google.tpl'
         page_uri=$node.url_alias
         item_count=$count
         view_parameters=$view_parameters
         item_limit=$page_limit}
{undef $page_limit $filter $count $children}

Cost

Every fetch is one or more database queries. Fetch what a template needs, with a limit, and keep the result in a variable instead of fetching the same thing twice. Parts of a page that many requests share can be cached with {cache-block}; see Template caching. The SQL tab of the Exp Debug bar shows the queries of a page (see Debugging templates).

How to print what a fetch returns: Outputting node and object data.

In this section

Contributors

Comments

Add a comment

Comments are read by a moderator before they appear.