Index within an Array

Author Message

Jorge estévez

Thursday 18 May 2006 9:15:26 am

Lets say I have an array of articles, I will make a loop and when accessing element 1 I
would like to print out the name of the first item and the name of the third item (offset
from the first)

something like:

item[index].name
and
item[index+3].name


	{section var=child loop=$list_items}

		// item within the loop
		{$child.name} //How to access the index?

		// offset from the current item being looped
		{$child.name} //How to access the index of the third [index+3] ?
	
	{/section}

I would like to understand how to access elements from an array using somekind of indexing.

Please help!

Diseño Web Cuba
Web Design Cuba
www.elfosdesign.com

Kristof Coomans

Thursday 18 May 2006 10:58:11 pm

Hi Jorge

If you're using eZ publish 3.6 or newer, I would suggest to use foreach instead of section (it is deprecated). You will find examples of how to use foreach in the technical manual: http://ez.no/doc/ez_publish/technical_manual/3_7/reference/template_control_structures/looping/foreach

The technical manual also contains more information on accessing array elements: http://ez.no/doc/ez_publish/technical_manual/3_7/templates/the_template_language/variable_usage (search for "index lookup")

Good luck!

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.