Forums / Developer / Global variable in a template

Global variable in a template

Author Message

Kedar Deshpande

Thursday 28 January 2010 5:59:38 pm

Hi, I have a template for the xml view of a object. For example:

<code>

<title>{attribute_view_gui attribute=$articleNode.data_map.title}</title>
<byline>{attribute_view_gui attribute=$articleNode.data_map.byline}</byline>
<image>{attribute_view_gui attribute=$articleNode.data_map.image}</image>

</code>

On this page, I have 2 nested 'for' loops that contain a value within that needs to be displayed once these loops are done with their output.

<code>

{foreach $node.data_map.selection.content as $obj_relations}
{foreach $obj_relations as $item}

...

{$value}

{/foreach}

{/foreach}

Value is : {$value}

</code>

The problem is that I'm getting a empty variable. I tried defining this variable outside the loop with {def $value='test'} and then setting it inside the loop but just end up with 'test'. Is there any way to set this variable when inside the loop?

thanks.

Damien MARTIN

Friday 29 January 2010 2:02:49 am

You should use the set template operator to modify an existing variable (def works too, but is not logical as far your variable has been already declared) :

{set $value = "your value"}

Documentation page : http://ez.no/doc/ez_publish/technical_manual/4_x/reference/template_functions/variables/set