我有一个名为category.nameNl的变量.当我转储它时,它工作正常并显示类别的名称.
{{ dump(category.nameNl) }}
现在,我想使用活动语言来使其动态变化,因此nameEn和nameDe也可以正常工作.我执行以下操作,但这不起作用:
{{ dump(category.name~app.request.locale|capitalize) }}
任何想法?
解决方法:
过滤运算符(|)的优先级高于串联运算符(〜),因此大写优先.
如果要大写结果字符串,则必须使用括号:
{{ dump((category.name~app.request.locale)|capitalize) }}
The operator precedence is as follows, with the lowest-precedence operators listed first: b-and, b-xor, b-or, or, and, ==, !=, , >=, <=, in, matches, starts with, ends with, .., +, -, ~, *, /, //, %, is, **, |, [], and .
标签:symfony,twig,php
来源: https://codeday.me/bug/20191026/1934811.html