Forums / Setup & design / Template - Building an array of IDs for further processing.

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 :)