Forums / Developer / Building an array inside a loop
Anja Lundin
Wednesday 09 February 2005 1:54:08 am
Hi,I would like to know if the is a way of buildning an array inside a loop. I would like the remaining items (see the code below) to be items in a new array. After that I want to count the items in the new array. Is it possible?
This is the loop, so far:
{section name=Child loop=fetch('content','list', hash(parent_node_id, $node.node_id))} {section-exclude match=$Child:item.data_map.category.content.enumobject_list.0.enumvalue|eq('kopes')} {section-exclude match=$Child:item.data_map.category.content.enumobject_list.0.enumvalue|eq('skankes')} {section-exclude match=$Child:item.data_map.category.content.enumobject_list.0.enumvalue|eq('bytes')} {*Here is where I'd like to build an array with the items that are not excluded*} {/section} {*Here is where I'd like to count the items in the new array*}
Thanks in advance!/Anja
------------------------------------ Anja Lundin Developer, Novitell AB Sweden www.novitell.se
Tom Couwberghs
Wednesday 09 February 2005 2:02:07 am
Try something like:
{let filtered_items=array()} {section name=Child loop=fetch('content','list', hash(parent_node_id, $node.node_id))} {section-exclude match=$Child:item.data_map.category.content.enumobject_list.0.enumvalue|eq('kopes')} {section-exclude match=$Child:item.data_map.category.content.enumobject_list.0.enumvalue|eq('skankes')} {section-exclude match=$Child:item.data_map.category.content.enumobject_list.0.enumvalue|eq('bytes')} {set filtered_items=$filtered_items|append($Child:item)} {/section} {$filtered_items|attribute(show)} {/let}
Wednesday 09 February 2005 2:13:25 am
Thanks Tom!The attribute(show), doesnt show anything. I guess it means the array is empty? I'll try to search on the webbpage and see if I find something more on arrays.
Wednesday 09 February 2005 3:36:53 am
OK i've found the problem. This trick doesn't work with section name. Try it like this:
{let filtered_items=array()} {section var=Child loop=fetch('content','list', hash(parent_node_id, $node.node_id))} ... {set filtered_items=$filtered_items|append($Child.item)} {/section} {/let}
Now the set and let are in the same scope, so that should work.
Wednesday 09 February 2005 4:32:05 am
It works now! Thanks a lot, Tom!/Anja