我想要做的是将imageowner(控制器返回的变量)与当前用户进行比较
<!-- image remove button -->
{% if {{ imageOwner }} == {{ app.user.username }} %} //Line 5
<p>You are the owner of this image</p>
<button onclick="deleteStuff()">deleted</button>
{% endif %}
但它会抛出此错误
A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "punctuation" of value "{" inLayoutBundle:Frontpage:content-bubble.html.twig at line 5
{{imageOwner}}和{{app.user.username}}返回正确的值,我认为是语法或逻辑错误
答案 0 :(得分:3)
使用
{% if imageOwner == app.user.username %} //Line 5
<p>You are the owner of this image</p>
<button onclick="deleteStuff()">deleted</button>
{% endif %}
在php中,{p> {{ imageOwner }}
比echo $imageOwner
更为纤细。因此,当您不想打印变量时,不需要使用{{}}
包装变量。