[SOLVED] Dynamic variable names values in page template loop
Posted: Mon Feb 02, 2015 5:33 pm
Not sure if this is possible but in a page template I need to be able to re-create variable names within a smarty loop and pull out their values.
In a page template there are 20 content blocks using a naming convention speaker_name_1, speaker_name_2, speaker_name_3 all assigned to same named variables. In a section loop I need to be able to recreate the name and get the value. i.e. equivalent in PHP
I thought this might work but it just gives the variable name as a string not the value.
In a page template there are 20 content blocks using a naming convention speaker_name_1, speaker_name_2, speaker_name_3 all assigned to same named variables. In a section loop I need to be able to recreate the name and get the value. i.e. equivalent in PHP
Code: Select all
for ($i=1;$i<=20;$i++) {
$block = 'speaker_name_' . $i;
$block;
}
Code: Select all
{section name=i start=1 loop=21}
{assign var="var_name" value="speaker_name_"|cat:"`$smarty.section.i.index`"}
{assign var="var_value" value=$var_name}
{$var_value}
{/section}