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

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 02:46:23
Script start
Timing: Jan 18 2025 02:46:23
Module start 'layout'
Timing: Jan 18 2025 02:46:23
Module start 'content'
Timing: Jan 18 2025 02:46:24
Module end 'content'
Timing: Jan 18 2025 02:46:24
Script end

Main resources:

Total runtime0.8644 sec
Peak memory usage4,096.0000 KB
Database Queries55

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0073 587.9141152.6250
Module start 'layout' 0.00730.0041 740.539139.4453
Module start 'content' 0.01140.8512 779.9844499.2734
Module end 'content' 0.86260.0017 1,279.25788.1641
Script end 0.8643  1,287.4219 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00380.4340160.0002
Check MTime0.00170.1926160.0001
Mysql Total
Database connection0.00130.148010.0013
Mysqli_queries0.809893.6808550.0147
Looping result0.00060.0636530.0000
Template Total0.829896.020.4149
Template load0.00190.214320.0009
Template processing0.828095.789320.4140
Template load and register function0.00020.024410.0002
states
state_id_array0.00090.104710.0009
state_identifier_array0.00190.219720.0009
Override
Cache load0.00160.1799300.0001
Sytem overhead
Fetch class attribute can translate value0.00060.064220.0003
Fetch class attribute name0.00160.187730.0005
XML
Image XML parsing0.00090.099520.0004
class_abstraction
Instantiating content class attribute0.00000.000930.0000
General
dbfile0.00110.1289160.0001
String conversion0.00000.001340.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
5content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1content/datatype/view/ezxmltags/strong.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/strong.tplEdit templateOverride template
1content/datatype/view/ezxmltags/emphasize.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/emphasize.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/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 16
 Number of unique templates used: 10

Time used to render debug report: 0.0001 secs