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.

eZ debug

Timing: Jan 18 2025 02:51:04
Script start
Timing: Jan 18 2025 02:51:04
Module start 'layout'
Timing: Jan 18 2025 02:51:04
Module start 'content'
Timing: Jan 18 2025 02:51:05
Module end 'content'
Timing: Jan 18 2025 02:51:05
Script end

Main resources:

Total runtime0.7601 sec
Peak memory usage4,096.0000 KB
Database Queries65

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0112 589.5938153.4531
Module start 'layout' 0.01120.0035 743.046939.3984
Module start 'content' 0.01480.7437 782.4453609.0703
Module end 'content' 0.75850.0015 1,391.515612.1641
Script end 0.7600  1,403.6797 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00390.5195160.0002
Check MTime0.00180.2362160.0001
Mysql Total
Database connection0.00120.154010.0012
Mysqli_queries0.692391.0767650.0107
Looping result0.00070.0891630.0000
Template Total0.709993.420.3549
Template load0.00210.275020.0010
Template processing0.707893.117720.3539
Template load and register function0.00010.012610.0001
states
state_id_array0.00270.349010.0027
state_identifier_array0.00190.245320.0009
Override
Cache load0.00180.2377410.0000
Sytem overhead
Fetch class attribute can translate value0.00080.100130.0003
Fetch class attribute name0.00150.196770.0002
XML
Image XML parsing0.00130.164930.0004
class_abstraction
Instantiating content class attribute0.00000.002080.0000
General
dbfile0.00120.1626240.0001
String conversion0.00000.001240.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
5content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
11content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezxmltags/quote.tpldatatype/ezxmltext/quote.tplextension/ezwebin/design/ezwebin/override/templates/datatype/ezxmltext/quote.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 27
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs