Reputation: 3711
I really like the smarty documentation but sometimes its hard to find easy stuff... so heres my question. Is it possible to set a var in a condition? theres a large template with many euro signs. now there is another new language but they not paying with euro. so instead of settung up a condition for the language around each euro sign. i want to use a var which is set at the start of my template once with the language condition like:
{if $lang eq 'ch'}
{*need to set "CHF" as a smarty or php var*}
{else}
{*need to set "EURO" as a smarty or php var*}
{/if}
<div class="payment">{$price} {*CHF or EURO var*}</div>
Upvotes: 4
Views: 12659
Reputation: 14863
{if $lang eq 'ch'}
<div class="payment">{$price} CHF</div>
{else}
<div class="payment">{$price} EURO</div>
{/if}
There's no need for a variable?
Upvotes: 0
Reputation: 741
{if $lang eq 'ch'}
{assign var="currency" value="CHF"}
{else}
{assign var="currency" value="EURO"}
{/if}
<div class="payment">{$price} {$currency}</div>
Upvotes: 8
Reputation: 449395
Why not set it outside the template, in the code, where you assign the price to the template?
I would argue that's where this belongs. Templates are supposed to control the presentation; anything to do with logic belongs in the code driving it.
Upvotes: 2