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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?