Forums / Developer / Multi-dimensional arrays in template language, how?

Multi-dimensional arrays in template language, how?

Author Message

Oliver Frommel

Wednesday 14 May 2008 6:14:06 am

Hello,

how do I create a multi-dimensional array in the eZ template language without static assignments? I tried several approaches but all of them failed.

a naive approach that does not work but illustrates the task:

{for 0 to 6 as $x}
{set $tmparr = array()}
{for 0 to 6 as $y}
{set $data[$x][$y] = $x|mul($y)}
{/for}
{/for}

So I tried to use a temporary one-dimensional array and assign it to a column/row of the 2-dim array, as in:

{for 0 to 6 as $x}
{set $tmparr = array()}
{for 0 to 6 as $y}
{set $tmparr = $tmparr|append($x|mul($y))}
{/for}
{set $data[$x]=$tmparr}
{/for}

My research showed that it is not possble make an assignment with something else than a "variable" on the left side of the assignment operator, according to http://issues.ez.no/6981 for instance.

So, how can I achieve what I want in the eZ template language?

Thanks
Oliver

André R.

Wednesday 14 May 2008 7:41:32 am

Something like this?

{def $data = array()
      $tmparr = array()}
{for 0 to 6 as $x}
    {set $tmparr = array()}
    {for 0 to 6 as $y}
        {set $tmparr = $tmparr|append( $x|mul($y) )}
    {/for}
    {set $data= $data|append( $tmparr )}
{/for}

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Oliver Frommel

Wednesday 14 May 2008 7:57:06 am

Yeah, that was it :) Thanks a lot, André
Best
Oliver

Piotrek Karaś

Wednesday 14 May 2008 1:17:38 pm

Will multi-dimentional arrays have easier support when template component is introduced to eZ Publish?
http://ezcomponents.org/docs/tutorials/Template#array
I believe eZ Publish and the component itself would benefit greatly (if it doesn't support that already).

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

Maxime Thomas

Sunday 18 May 2008 10:23:43 pm

Hi,

It has been a big feature I've requested for a long time now, but it never appends... :-(
By the way, it seems it will be soon available in eZ 4.5, it will come with the ezcTemplate with some other cool stuff as : disappearing of and and or operators (yes !) and direct operations (like {5*3})...

Max

Maxime Thomas
[email protected] | 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