|
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 |
gordonisnz Smarty Regular
Joined: 05 Sep 2009 Posts: 70
|
Posted: Sun Jan 17, 2021 5:24 am Post subject: Help with syntax. |
|
|
Hello. Ive got a syntax error in an apparently simple piece of Smarty template.
basically ive got 3 layers of FOREACH code :-
Code: |
{foreach from=$regions key=k item=v}
{$tmpa = ksort($v)}
{foreach from=$v key=ka item=va}
<option value="{$k}-{$ka}">{$k} {$ka}</option>
{$tmpb = ksort($va)}
{foreach from=$va key=kaa item=vaa}
<option value="{$k}-{$ka}-{$kaa}">{$k} {$ka} {$kaa}</option>
{/foreach}
{/foreach}
{/foreach}
|
Basically, ive got country, region, and city in an array and i'm looping through it OK - this part works.
Each value is in keys $k $ka and $kaa
The problem is, I want to record the region/country/city in a value (this is OK - $gotregion ).
I'm wanting to test if the current area matches the region/are ive already got and then add the selected=selected code..
Code: |
<option value="{$k}-{$ka}-{$kaa}" {if($gotregion=="{$k}-{$ka}-{$kaa}")}selected="selected"{/if}>{$k} {$ka} {$kaa}</option>
|
HOWEVER i'm getting syntax error.
Can anyone see any obvious (not to me) problems with the 'selected' syntax ? |
|
Back to top |
|
gordonisnz Smarty Regular
Joined: 05 Sep 2009 Posts: 70
|
Posted: Sun Jan 17, 2021 5:36 am Post subject: |
|
|
Ive fixed it.
Code: |
{foreach from=$va key=kaa item=vaa}
{assign var=TEMP value="$k-$ka-$kaa"}
<option value="{$k}-{$ka}-{$kaa}" {if ($gotregion=="$TEMP")}selected="selected"{/if}>{$k} {$ka} {$kaa}</option>
|
|
|
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
|