douningle7944 2017-11-16 17:21
浏览 74
已采纳

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.

  • 写回答

1条回答 默认 最新

  • droxy80248 2017-11-16 17:34
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了