如何在树枝中连接字符串 [英] How to concatenate strings in twig
本文介绍了如何在树枝中连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人知道如何在 twig 中连接字符串吗?我想做类似的事情:
Anyone knows how to concatenate strings in twig? I want to do something like:
{{ concat('http://', app.request.host) }}
推荐答案
这应该可以正常工作:
{{ 'http://' ~ app.request.host }}
要在同一个标签中添加过滤器——比如trans"——使用
To add a filter - like 'trans' - in the same tag use
{{ ('http://' ~ app.request.host) | trans }}
正如 Adam Elsodaney 指出的,您也可以使用 字符串插值,这确实需要双引号字符串:
As Adam Elsodaney points out, you can also use string interpolation, this does require double quoted strings:
{{ "http://#{app.request.host}" }}
这篇关于如何在树枝中连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文