Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Help with syntax.

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
gordonisnz
Smarty Regular


Joined: 05 Sep 2009
Posts: 70

PostPosted: Sun Jan 17, 2021 5:24 am    Post subject: Help with syntax. Reply with quote

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}&nbsp;{$ka}</option>
{$tmpb = ksort($va)}
{foreach from=$va key=kaa item=vaa}

<option value="{$k}-{$ka}-{$kaa}">{$k}&nbsp;{$ka}&nbsp;{$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}&nbsp;{$ka}&nbsp;{$kaa}</option>


HOWEVER i'm getting syntax error.

Can anyone see any obvious (not to me) problems with the 'selected' syntax ?
Back to top
View user's profile Send private message
gordonisnz
Smarty Regular


Joined: 05 Sep 2009
Posts: 70

PostPosted: Sun Jan 17, 2021 5:36 am    Post subject: Reply with quote

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}&nbsp;{$ka}&nbsp;{$kaa}</option>


Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP