4

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>
1
  • sorry forgot... its not my plugin/php and maybe its not allowed for me to touch it ;) and all in all... i prefer a smarty solution. thx Commented Dec 2, 2011 at 11:55

4 Answers 4

8
{if $lang eq 'ch'}
    {assign var="currency" value="CHF"}
{else}
    {assign var="currency" value="EURO"}
{/if}

<div class="payment">{$price} {$currency}</div>
Sign up to request clarification or add additional context in comments.

1 Comment

nice... didnt know its possible to assign in smarty template itself. will remember it for QAD solutions or if a miss some access rights again ;) thanks works.
3

Short way:

{assign currency ($lang eq 'ch') ? 'CHF' : 'EURO'}

Comments

2

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.

1 Comment

ok i tried like i thought... no access to the plugin only to the HTML file... customers...... so i not even prefer smarty solution.. theres no other way for me right now.
0
{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?

2 Comments

read the question there are many euro signs on the page (like 40)... and i dont want to do that condition 40 times ;)
Ah, I overlooked that. Still think this is better done within the php-file itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.