Madzmar Ullang Madzmar Ullang - 3 months ago 64
Smarty Question

Smarty concat string to variable to get another variable

Hi I would like to concat a string into a variable to retrieve the value of another variable let say the example is below

# Variable one
filter_var = "The value to get"
name = "var"

# now I want to retrieve the value of filter_var. What I was thinking is something like this
{{ "filter_".name }} # assuming "name" variable has dynamic content

How do I solve this?


Another sample is below

traduction.Product = "the value"
categorie = "Product"

# Now I'm trying to output the value in a div tag
<div>{{ traduction.{{categorie}} }}</div>

but I'm getting an error of Expected name or number.

Answer Source

Assuming you're using Smarty 3, you can use this:


It's mentioned in the "Variable variables" section on this page:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download