Forums / Setup & design / loop with {section} syntax to {foreach} syntax

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