Stratboy Stratboy - 7 months ago 177
Smarty Question

how to assign a function's expression to a variable in smarty

say I've got a text like this:

{l s='Total'}

'l' is a function. The string 'Total' in fact will be a translation: 'l' will output that. I would need to assign the resulting translation to another smarty variable. Is it possible and how to?

Answer Source

You can do it with assign var

{assign var='translatedString' value={l s='Total'}} 

And then somewhere else in the template file to output it.


Or with capture

{capture name=translatedString}
    {l s='Total'}

And output with


You could also assign capture to a var

{assign var='capturedVar' value=$smarty.capture.translatedString}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download