[英]Add a twig variable to an <img>
I have an image showing up like that: 我有这样的图像显示:
src="{{ asset('./images/cours/zumba.jpg') }}"
Then I define a foo variable: 然后定义一个foo变量:
{% set foo = 'zumba' %}
Then I try to insert the variable foo in the <img>
然后我尝试将变量foo插入
<img>
src="{{ asset('./images/cours/{{ foo }}.jpg') }}"
The image doesn't show up, any ideas? 图片没有显示,有什么想法吗? Thank you in advance.
先感谢您。
Yes, you must rather do : 是的,您必须这样做:
src="{{ asset('./images/cours/' ~ foo ~ '.jpg') }}"
~
is to concatenate strings, so it concatenates your variable and the placeholder path that you have. ~
是连接字符串,因此它可以连接变量和具有的占位符路径。
See the "Other operators" section here for the complete documentation 有关完整的文档,请参见此处的“其他运算符”部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.