eZpedia : The Free eZ Publish CMS Documentation Encyclopedia

Snippet: Template logic to fetch random content object

Table of contents:

This is a Stub article. Help the eZ Publish community by expanding it!

Example template

The following example shows how to fetch a random content objeect, an image in this example.

{def $nrimages=fetch( 'content', 'tree_count', hash( 'parent_node_id', 2, 'class_filter_type', 'include', 'class_filter_array', array('image') ) )}
{def $randomimage=fetch( 'content', 'tree', hash( 'parent_node_id', 2, 'class_filter_type', 'include', 'class_filter_array', array('image'), 'offset', rand(0, dec($nrimages)), 'limit', 1 ) )}
{content_view_gui content_object=$randomimage[0] view=embed}

Reference

  • Forum: N/A

Article provided by eZpedia

All text is available under the terms of the GNU Free Documentation License

Powered by eZ Publish Community Project 4.2011

Hosted by Swiss eZ Publish partner YMC