简体   繁体   English

Twig中资产声明中的变量

[英]A variable inside an asset declaration in Twig

My inline style looks like: 我的内联样式如下:

style="background-image: url({{ asset('bundles/testblog/images/id.jpg') }});"

the part id of the url must change depending on a varibale. url的part id必须根据varibale而改变。 How can I make this happen inside the asset. 我怎样才能在资产内部实现这一点。

I tried : 我试过了 :

style="background-image: url({{ asset('bundles/testblog/images/'{{variable}}'.jpg') }});" 

But to no avail. 但无济于事。

Use ~ for concatenation , 使用~进行连接

style="background-image: url({{ asset('bundles/testblog/images/' ~ variable ~ '.jpg') }});"

Also, 也,

You don't need to nest {{ ... }} delimiters. 您不需要嵌套{{ ... }}分隔符。 The ones you used to wrap asset() call are also used to print any other variable they contain. 用于包装asset()调用的那些也用于打印它们包含的任何其他变量。

style="background-image: url({{ asset('bundles/testblog/images/' ~ variable ~ '.jpg') }});" 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM