|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
bene82 Smarty n00b
Joined: 09 Sep 2013 Posts: 1
|
Posted: Mon Sep 09, 2013 7:56 am Post subject: Get Smarty variable dynamically |
|
|
I have these variables:
Code: | $idben47 Smarty_Variable Object (3)
->value = "0.00"
->nocache = false
->scope = "Smarty root"
$idben48 Smarty_Variable Object (3)
->value = "120.00"
->nocache = false
->scope = "Smarty root"
$idben49 Smarty_Variable Object (3)
->value = "0.00"
->nocache = false
->scope = "Smarty root"
|
How I can dynamically get these in my tpl file?
In my tpl file I already have the $id_attribute variable (47,48,49 in this case). I'm trying to do something like this:
Code: |
<span>Prezzo:{$idben.id_attribute}</span>
|
But the system don't get the variable...
Thank you in advance |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Sep 09, 2013 1:33 pm Post subject: |
|
|
Do you have flexibility how things are assigned to the template? If so, you are better off structuring your data in a way that does not require dynamic variable naming. Such as:
Code: | $smarty->assign('idben' => array(
'47' => '0.00',
'48' => '120.00',
'49' => '0.00'
)); |
Then in template:
Code: | {$idben.$id_attribute} |
Otherwise you could assign everything under a variable so you can use:
Code: | {assign var="tmp" value="idben23"}
{$myarray.$tmp} |
Otherwise you will have to use a plugin to do the variable variable thing, which there are some on the forum if you search. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Sep 09, 2013 3:37 pm Post subject: |
|
|
Smarty 3 does support variable variable names. In your examole you could use
Code: | {$idben{$id_attribute}} |
|
|
Back to top |
|
anaas5 Smarty n00b
Joined: 04 Oct 2013 Posts: 1
|
Posted: Fri Oct 04, 2013 9:40 am Post subject: |
|
|
Knowledgeable post! |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|