Template - Building an array of IDs for further processing.

Author Message

Michael Zeidler

Sunday 01 May 2005 3:13:18 pm

Lets assume that we have given an array of contentObjects ($contentobject_array). This array should be iterated to extract the ID of each element used to fill a new array ($folder_node_id_array). Outside of the iteration ({section}-template-function) the new generated array must be available for further processing.

The template code:
------------------

{let folder_node_id_array=array()}
  {section var=folder loop=$contentobject_array}
    {set folder_node_id_array=$folder_node_id_array|append($folder.item.main_node.node_id) }
   A:{$folder_node_id_array|attribute(show)}
  {/section}
<br>B:{$folder_node_id_array|attribute(show)}
{/let}

At A: the correct new array is displayed as expected. But at B: there is not even something displayed. The variable $folder_node_id_array seems to be vanished, although its still in the scope of the let-template-function.
According to the description of the let-template-function I quote the following:
"Assigns one or more variables <b>within its tags</b>. The assigned variables are freed (released) at the end tag."

-------------------------------------------------------------------------------------------
join #ezpublish on irc.freenode.org

Michael Zeidler

Tuesday 03 May 2005 2:08:50 am

Frederik Holljen posted a running solution on IRC which i could adapt to my needs.
Thank you Frederik.

[10:51] <@ fh | >tested the logic in 3.5.1 like this:
[10:52] <@ fh | >{let folder_node_id_array=array()}
[10:52] <@ fh | > {section var=folder loop=array(1,2,3,4)}
[10:52] <@ fh | > {set folder_node_id_array=$folder_node_id_array|append($folder) }
[10:52] <@ fh | > A:{$folder_node_id_array|attribute(show)}
[10:52] <@ fh | > {/section}
[10:52] <@ fh | ><br>B:{$folder_node_id_array|attribute(show)}
[10:52] <@ fh | >{/let}

-------------------------------------------------------------------------------------------
join #ezpublish on irc.freenode.org

Frederik Holljen

Tuesday 03 May 2005 2:17:04 am

No problem :)

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 01:21:56
Script start
Timing: Jan 19 2025 01:21:56
Module start 'layout'
Timing: Jan 19 2025 01:21:56
Module start 'content'
Timing: Jan 19 2025 01:21:57
Module end 'content'
Timing: Jan 19 2025 01:21:57
Script end

Main resources:

Total runtime0.8560 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.0048 589.4141152.6563
Module start 'layout' 0.00480.0026 742.070339.5078
Module start 'content' 0.00740.8471 781.5781545.0469
Module end 'content' 0.85450.0015 1,326.625012.0938
Script end 0.8560  1,338.7188 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00320.3719160.0002
Check MTime0.00130.1495160.0001
Mysql Total
Database connection0.00050.063010.0005
Mysqli_queries0.802393.7195570.0141
Looping result0.00060.0749550.0000
Template Total0.832097.220.4160
Template load0.00200.232620.0010
Template processing0.830096.960320.4150
Template load and register function0.00020.028510.0002
states
state_id_array0.00030.030510.0003
state_identifier_array0.00100.122220.0005
Override
Cache load0.00170.2006260.0001
Sytem overhead
Fetch class attribute can translate value0.00140.160720.0007
Fetch class attribute name0.00130.147350.0003
XML
Image XML parsing0.00200.233820.0010
class_abstraction
Instantiating content class attribute0.00000.001860.0000
General
dbfile0.00130.1569220.0001
String conversion0.00000.000940.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/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
6content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.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: 7

Time used to render debug report: 0.0001 secs