variable variables

Author Message

Patrick Kaiser

Thursday 30 March 2006 8:33:25 am

Hi,

I would like to use variable variables in a template, and was sure to have done so before, but i can neither find the template nor can i get this running.

I have a class that consists of several elements of the same datatype (object relation), following the naming convention related_[number], where number is an int from 1 to 4.

The following code doesnt work and is only an example. What i want to archive is that [$number] gets substituted by the actual value of $number:

{def $out=array() $myobj=$node.object.data_map}
{for 0 to 4 as $number}
  {set $out = $out|append( hash( 'link', $myobj.related_[$number].content.main_node.url_alias,
'maincat', $myobj.related_[$number].content.main_node.path.1.name,
'teaser', $myobj.related_[$number].main_node.data_map.teaser.content ))}
{/for}

Any ideas would be highly appreciated!

Thanks,

Patrick


Best regards,

Patrick

J Jones

Tuesday 07 August 2007 8:35:20 am

This is an old post I know. And I don't even have a solution.

I need to change the value for a dynamic variable being used in a foreach-loop.

So that I can access i.e. $myvariable later on the page. But there seems to be no option to do this with variables in EZ.

It even surprises me more that I seem to be one of the few who would need this?

Jesper

Patrick Kaiser

Tuesday 07 August 2007 12:32:37 pm

At least for my original problem I found the solution in between.
Given the case you want to access attributes that follow a certain naming convention (ie. attribute_1, attribute_2, attribute_3, etc) you could do the following:

{def $attribute_pre='attribute_' $tmp=''}
{for 0 to 4 as $number}
  {set $tmp=concat( $attribute_pre, $number )}
  {$node.data_map[$tmp].content}
{/for}


Best regards,

Patrick

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 19 2025 00:35:59
Script start
Timing: Jan 19 2025 00:35:59
Module start 'layout'
Timing: Jan 19 2025 00:35:59
Module start 'content'
Timing: Jan 19 2025 00:35:59
Module end 'content'
Timing: Jan 19 2025 00:35:59
Script end

Main resources:

Total runtime0.0230 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0099 587.7891152.6094
Module start 'layout' 0.00990.0041 740.398439.4141
Module start 'content' 0.01400.0063 779.812589.3984
Module end 'content' 0.02030.0026 869.210934.3047
Script end 0.0229  903.5156 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002912.6880140.0002
Check MTime0.00114.8722140.0001
Mysql Total
Database connection0.00166.943910.0016
Mysqli_queries0.004720.326330.0016
Looping result0.00000.099610.0000
Template Total0.00219.210.0021
Template load0.00093.957710.0009
Template processing0.00125.211610.0012
Override
Cache load0.00062.759910.0006
General
dbfile0.00031.323480.0000
String conversion0.00000.095540.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