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
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

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 31 2025 03:30:08
Script start
Timing: Jan 31 2025 03:30:08
Module start 'layout'
Timing: Jan 31 2025 03:30:08
Module start 'content'
Timing: Jan 31 2025 03:30:08
Module end 'content'
Timing: Jan 31 2025 03:30:08
Script end

Main resources:

Total runtime0.0259 sec
Peak memory usage6,144.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0063 588.2656151.2266
Module start 'layout' 0.00630.0041 739.4922220.7344
Module start 'content' 0.01040.0140 960.22661,001.9609
Module end 'content' 0.02440.0015 1,962.187537.9922
Script end 0.0259  2,000.1797 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.003714.3716140.0003
Check MTime0.00114.3158140.0001
Mysql Total
Database connection0.00145.541110.0014
Mysqli_queries0.00238.753130.0008
Looping result0.00000.050610.0000
Template Total0.00114.210.0011
Template load0.00083.244210.0008
Template processing0.00020.941810.0002
Override
Cache load0.00062.232510.0006
General
dbfile0.00207.764480.0003
String conversion0.00000.023940.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs