Forums / Setup & design / Merge two arrays

Merge two arrays

Author Message

paul bolger

Sunday 18 November 2007 3:40:22 pm

I have a news items folder, created by doing a fetch/list on a subfolder, sorted by an attribute (start time, they are calendar events).

I'd like to add nodes from a second folder, and have them appear every x items in the resulting array (folder 1 item 1, folder 1 item 2, folder 2 item 1, folder 1 item 3 etc). the items from the second folder would need to be sorted by priority. I'd prefer to not be locked into having to stipulate the actual priority numbers for the items in the second folder (users hate that sort of thing).

Can anyone suggest a good approach to this?

Paul Bolger

Maxime Thomas

Monday 19 November 2007 5:37:16 am

Hi,

You can use two arrays resulting from a fetch and foreach loop :

{def $index_for_table2=0}
{foreach $table1 as $k => $t1}
Print data for $t1 : {node_view_gui node=$t1}

{delimiter}

{if $k|mod(3)|eq(1)}

Print data for $t2 ! {node_view_gui node=$table2[$index_for_table2]}
{set $index_for_table2=$index_for_table2|inc()}

{/if}

{/delimiter}

{/foreach}
{undef $index_fot_table2}

Reference :
http://ez.no/doc/ez_publish/technical_manual/3_10/reference/template_control_structures/looping/foreach

Maxime Thomas
maxime.thomas@wascou.org | www.wascou.org | http://twitter.com/wascou

Company Blog : http://www.wascou.org/eng/Company/Blog
Technical Blog : http://share.ez.no/blogs/maxime-thomas

paul bolger

Tuesday 20 November 2007 4:35:18 pm

Thanks, That sound like it would do the job.

Paul Bolger