loop with {section} syntax to {foreach} syntax

Author Message

Pascal France

Thursday 15 March 2007 11:39:03 am

Hi,

I just would like to use the {foreach} syntax to write the loop which is in content/view/full.tpl template:

{section name=ContentObjectAttribute loop=$object.contentobject_attributes}
{attribute_view_gui attribute=$ContentObjectAttribute:item}
{/section}

According with the foreach doc I wrote:

{foreach $ContentObjectAttribute as  $object.contentobject_attributes}
{if eq($ContentObjectAttribute,body)}
{attribute_view_gui attribute=$ContentObjectAttribute:item}
{/if}
{/foreach}

but this doesn't work.

Regards

Pascal

Ce qui embellit le désert c'est qu'il cache un puits... quelque part... (A. de Saint-Exupéry) - http://luxpopuli.fr/eZ-Publish

Claudia Kosny

Thursday 15 March 2007 2:18:24 pm

Hi Pascal

You have the variables the wrong way around. This should (hopefully) be correct:

{foreach  $object.contentobject_attributes as $ContentObjectAttribute}
    {attribute_view_gui attribute=$ContentObjectAttribute}
{/foreach}

The if statement in your code will most likely not work because $ContentObjectAttribute is an object, which you want to compare with the string 'body'. Therefore I left it out.

Claudia

Pascal France

Thursday 15 March 2007 4:20:23 pm

Thanks a lot Claudia,

The two working syntaxes are:

<section name=ContentObjectAttribute loop=$object.contentobject_attributes>
<if eq($ContentObjectAttribute:item.contentclass_attribute.identifier,body)>
<attribute_view_gui attribute=$ContentObjectAttribute:item>
</if>
</section>

and:

{foreach  $object.contentobject_attributes as $ContentObjectAttribute}
{if eq($ContentObjectAttribute.contentclass_attribute.identifier,body)}
{attribute_view_gui attribute=$ContentObjectAttribute}
{/if}
{/foreach}

So we have to:
- permutate "ContentObjectAttribute" and "object.contentobject_attributes"
- remove ":item"

Regards

Pascal

Ce qui embellit le désert c'est qu'il cache un puits... quelque part... (A. de Saint-Exupéry) - http://luxpopuli.fr/eZ-Publish

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 18 2025 10:34:57
Script start
Timing: Jan 18 2025 10:34:57
Module start 'layout'
Timing: Jan 18 2025 10:34:57
Module start 'content'
Timing: Jan 18 2025 10:34:57
Module end 'content'
Timing: Jan 18 2025 10:34:57
Script end

Main resources:

Total runtime0.5808 sec
Peak memory usage4,096.0000 KB
Database Queries57

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0079 589.1797152.6406
Module start 'layout' 0.00800.0031 741.820339.4766
Module start 'content' 0.01110.5683 781.2969502.4141
Module end 'content' 0.57930.0014 1,283.710912.1250
Script end 0.5807  1,295.8359 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00340.5925160.0002
Check MTime0.00150.2553160.0001
Mysql Total
Database connection0.00110.182810.0011
Mysqli_queries0.531091.4391570.0093
Looping result0.00050.0876550.0000
Template Total0.546894.220.2734
Template load0.00190.333520.0010
Template processing0.544993.819620.2724
Template load and register function0.00020.026510.0002
states
state_id_array0.00140.242910.0014
state_identifier_array0.00130.223220.0006
Override
Cache load0.00160.2765280.0001
Sytem overhead
Fetch class attribute can translate value0.00050.092120.0003
Fetch class attribute name0.00120.206430.0004
XML
Image XML parsing0.00020.035320.0001
class_abstraction
Instantiating content class attribute0.00000.001430.0000
General
dbfile0.00070.1212100.0001
String conversion0.00000.001840.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
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
8content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
5content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 19
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs