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

eZ debug

Timing: Jan 20 2025 14:37:14
Script start
Timing: Jan 20 2025 14:37:14
Module start 'content'
Timing: Jan 20 2025 14:37:15
Module end 'content'
Timing: Jan 20 2025 14:37:15
Script end

Main resources:

Total runtime1.0230 sec
Peak memory usage4,096.0000 KB
Database Queries204

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0074 589.1016180.8125
Module start 'content' 0.00740.9000 769.9141657.7813
Module end 'content' 0.90740.1156 1,427.6953337.0547
Script end 1.0230  1,764.7500 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00380.3731210.0002
Check MTime0.00150.1427210.0001
Mysql Total
Database connection0.00060.062210.0006
Mysqli_queries0.947592.61272040.0046
Looping result0.00180.17742020.0000
Template Total0.991096.920.4955
Template load0.00220.212920.0011
Template processing0.988896.650520.4944
Template load and register function0.00020.014910.0002
states
state_id_array0.00120.115410.0012
state_identifier_array0.00100.101820.0005
Override
Cache load0.00180.1757430.0000
Sytem overhead
Fetch class attribute can translate value0.00100.100750.0002
Fetch class attribute name0.00140.133080.0002
XML
Image XML parsing0.00180.178050.0004
class_abstraction
Instantiating content class attribute0.00000.001780.0000
General
dbfile0.00670.6536410.0002
String conversion0.00000.000430.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

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
5content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
9content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
6content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 26
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs