Smarty将字符串连接到变量以获取另一个变量

Smarty将字符串连接到变量以获取另一个变量

问题描述:

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?

Edit:

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.

您好我想将一个字符串连接成一个变量来检索另一个变量的值,让我们说下面的例子如下 p>

  #Variable one 
filter_var =“要获取的值”
name =“var”
 
#现在我想要检索filter_var的值。 我在想的是这样的事情
 {{“filter _”。name}} #preiting“name”变量有动态内容
  code>  pre> 
 
 

我如何解决这个问题 ? p>

编辑: p>

另一个示例位于 p>

  traduction.Product =“the value  “
categorie =”Product“
 
#现在我正在尝试输出div标签中的值
&lt; div&gt; {{traduction。{{categorie}}}}&lt; / div&gt; 
  代码>  pre> 
 
 

但我收到了预期名称或号码的错误。 p> div>

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

{$filter_{$name}}

It's mentioned in the "Variable variables" section on this page: https://www.smarty.net/docs/en/language.syntax.variables.tpl