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.

eZ debug

Timing: Jan 19 2025 12:48:52
Script start
Timing: Jan 19 2025 12:48:52
Module start 'layout'
Timing: Jan 19 2025 12:48:52
Module start 'content'
Timing: Jan 19 2025 12:48:53
Module end 'content'
Timing: Jan 19 2025 12:48:53
Script end

Main resources:

Total runtime0.7625 sec
Peak memory usage4,096.0000 KB
Database Queries54

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0066 589.1406152.6094
Module start 'layout' 0.00660.0033 741.750039.4141
Module start 'content' 0.00990.7513 781.1641525.1953
Module end 'content' 0.76120.0012 1,306.35948.1875
Script end 0.7625  1,314.5469 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00310.4082160.0002
Check MTime0.00120.1579160.0001
Mysql Total
Database connection0.00140.187410.0014
Mysqli_queries0.719694.3730540.0133
Looping result0.00040.0509520.0000
Template Total0.733696.220.3668
Template load0.00200.258220.0010
Template processing0.731695.944820.3658
Template load and register function0.00010.018610.0001
states
state_id_array0.00100.137010.0010
state_identifier_array0.00100.136520.0005
Override
Cache load0.00150.1997190.0001
Sytem overhead
Fetch class attribute can translate value0.00040.058620.0002
Fetch class attribute name0.00080.110330.0003
XML
Image XML parsing0.00080.099320.0004
class_abstraction
Instantiating content class attribute0.00000.000830.0000
General
dbfile0.00080.1006160.0000
String conversion0.00000.001240.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
4content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 12
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs