Path

ez.no / ezpublish / documentation / customization / tips & tricks / fetch function examples


Fetch Function examples

These documentation pages are no longer maintained. Please visit the new documentation site.

Fetch Function

The fetch function is a very useful template function, but unfortunately it's (up to now) very poorly documented. An example of using it is shown in Template Language But this page will try to explain the details.

fetch(<module>,<function>,<parameters>)

It takes 3 arguments:

<module> (string)

<function> (string)

<parameters> (associative array)

The function and its parameters are defined in [module]/function_definition.php.

Module: content

Functions: list, list_count, tree, tree_count, node

Parameters:

  • parent_node_id[integer]
  • node_id[integer] (only for function 'node')
  • sort_by[array] default: false

first array field is the field to sort:

 
  • "class_identifier"
  • "class_name"
  • "depth"
  • "modified"
  • "name"
  • "path"
  • "priority"
  • "published"
  • "section"

second array field is the order:

 
  • "true()" -> ascending
  • "false()" -> descending
  • offset[integer] default: false
  • limit[integer] default: false
  • depth[integer] default: 1
  • class_id[integer] default: false unused?
  • class_filter_type[string] default: false
 
  • "include"
  • "exclude"
  • class_filter_array[array] default: false
 

list of class ids

Examples:

Fetching subnodes of parent node 5, but only of class ids 2 (e.g. categories):

fetch( 'content', 'list', hash(parent_node_id, 5, 

class_filter_type, "include", class_filter_array, array(2))

Fetching node with node_id 23:

fetch( 'content', 'node', hash(node_id, 23))

Fetching nodes from a specific folder (50) and sorting it on an arbitrary attribute (the number (158) is the attribute number as listed when you view the definition of a content class).

fetch('content','list',

       hash(parent_node_id, 50,

           sort_by, array(array('attribute',false(),158))))

Fetching subnodes of parent node 10 and sorting ascending by name:

fetch( 'content', 'list', hash(parent_node_id, 10, "sort_by", array("name", true())))

If you want to fetch the "full" view of an object into the current place, it seems as

{let myvar=fetch(content,node,hash(node_id,62))}

{node_view_gui view=full content_node=$myvar}

{/let}

won't work (it complains about the whitespace being all wrong, whereas

{let children=fetch(content,node,hash(node_id,62))}

{node_view_gui view=full content_node=$children}

{/let}

will work without any trouble. Only difference being the variable name.

Feel free to add more about other modules, functions and examples!

Comments

is it posible to sort by class attribute?

is it posible to sort by class attribute?
For example, to sort users by lastname or by birthdate.

Fetching items with various locations

It appears that parent_node_id can be an array as well - allowing you to fetch from multiple locations with the one fetch

http://ez.no/community/forum/setu...etching_items_with_various_locations

To fetch on nodes beginning on certain character 3.2-3+

Sirs,

this code proved to be useful for me.

If you need to fetch nodes, which attribute nr. X (181 on the example) starts on some character (k in this case), try this:

{section loop=fetch( 'content', 'list', hash( parent_node_id, 1118 , attribute_filter, array( 'or', array( 181, '>=', 'k' ) )) ) }

<a href={$:item.url_alias|ezurl}>{$:item.name}</a><br>

{/section}

Hix

just.. :)

-snip-
{let myvar=fetch(content,node,hash{node_id,62))}
{node_view_gui view=full content_node=$myvar}
{/let}

won't work (it complains about the whitespace being all wrong, whereas
-snip-

the above example won't work, thats right - but not the variablename is the reason, rather the "hash{" instead of "hash("

Contents

Customization

Access control
eZ publish API Documentation
Content structure
Custom design
Components
Tips & Tricks
    Debugging templates
    Javascript in templates
    Fetching current user
    Showing related objects
    Show which templates are used
    Fetching the ID of the parent
    One Article Folder
    Creating tree menus
    How can I use my own php script insid...
    Hiding attribute content
    Splitting an article over several pages
    Accessing section id in pagelayout
    List articles in folder
    Creating nice URLs
    Alt tag on images
    Improve the pagelayout.tpl
    Clean HTML tags
    Insert javascript call inside ezpub d...
    3rd party applications
    Fetch Function examples
    Display more than 15 items on your co...
    Including PHP files in templates
    Redirecting after content publishing
    HowTo see if article has an image
    Date and Time Formats
    Forms processing example: store user...
    Adjust Timezone
    Adding a Remove Button/Image
    Find the age in years for an object
    Editing, creating and removing conten...
    Indexing binary files with IFilters o...
Troubleshooting


Created

12/04/2003
10:03:47 pm
by Paul Borgermans

Last updated

25/08/2004
8:45:36 am
by kracker

Authors

Paul Borgermans
Wolfgang Hofbauer
Gabriel Ambuehl
Bård Farstad
Bjørn Reiten
Derick Rethans
kracker



This page is part of the eZ Publish documentation. The documentation is available under the GNU Free Documentation License. All contributions will be released under the terms of this license.