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

Smarty concat string to variable to get another variable

嗨,我想将一个字符串连接到一个变量中以检索另一个变量的值,假设示例如下

# 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

我该如何解决这个问题?

编辑:

下面是另一个示例

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

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

但我收到“预期名称或号码”错误。

假设您使用的是 Smarty 3,您可以使用这个:

{$filter_{$name}}

在本页的 "Variable variables" 部分中提到:https://www.smarty.net/docs/en/language.syntax.variables.tpl