ez.no / ezpublish / documentation / customization / tips & tricks / fetch function examples
These documentation pages are no longer maintained. Please visit the new documentation site.
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.
Parameters:
first array field is the field to sort:
|
second array field is the order:
|
|
|
list of class ids |
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?
esu vytis
Friday 16 December 2005 5:47:31 pm
For example, to sort users by lastname or by birthdate.
Fetching items with various locations
Bruce Morrison
Friday 30 July 2004 1:04:56 am
http://ez.no/community/forum/setu...etching_items_with_various_locations
To fetch on nodes beginning on certain character 3.2-3+
New User
Monday 08 December 2003 9:19:46 pm
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.. :)
New User
Monday 11 August 2003 5:04:58 pm
{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("