Working with Arrays and Nodes

Author Message

Alejandro Dominguez

Wednesday 15 June 2011 2:51:54 am

Hello folks,

I have created a fetch to extract some nodes and now I would like to create an array with some of the nodes. If they pass a condition I will insert it in the array.

However I'm not able to create the right code to insert in the array.

I created an Array

 {def $myarray=Array()}

and then I tried to insert it with this sentence

{set $myarray[$counter]=$nodes[$to_display]}

I have also tried the insert

 

<span class="line">{$myarray | insert( 0, $nodes[$to_display] )}</span>

I think it's a noob syntax problem :$ . Can you help me?

 

Cheers,

Alejandro

Carlos Revillo

Wednesday 15 June 2011 3:42:42 am

hi Alejandro. i think what you need is append function. something like:

 {def $myarray = array()}
{set $myarray = $myarray|append( $node )}

but, without knowing properly what you are trying to achieve, i would say, in general is not a good idea to fetch all nodes and add them to another array only if they pass specific conditions. 

if those nodes are taken by a fetch, i would go for a way (probably a custom function or whatever) trying to only return the nodes you need from database, instead of fetching all if you don't need all of them. 

Marko Žmak

Wednesday 15 June 2011 7:03:12 am

"

if those nodes are taken by a fetch, i would go for a way (probably a custom function or whatever) trying to only return the nodes you need from database, instead of fetching all if you don't need all of them. 

"

An extended attribute filter would probably be the best.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Carlos Revillo

Wednesday 15 June 2011 7:06:54 am

"

An extended attribute filter would probably be the best.

"

yep. sure!. or even better, an ezfind query :).

Alejandro Dominguez

Friday 17 June 2011 2:03:16 am

Hi Carlos & Marko!

The Append solution has worked well!  The extended attribute filter seems to be a better solution, so I'm going to try this now.

 

Thanks for your answers :)

 

cheers

Alejandro

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.