0

What im trying to do is compare the imageowner (variable returned by the controller) with the current user

<!-- 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 %}

but it throws this error

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

the {{ imageOwner }} and {{ app.user.username }} return the right values, I think its a syntax or logical error

1
  • 2
    You don't need {{ }} when you are in a statement Commented Apr 14, 2014 at 9:01

1 Answer 1

3

Use

 {% if imageOwner  == app.user.username %} //Line 5
    <p>You are the owner of this image</p>

    <button onclick="deleteStuff()">deleted</button>
 {% endif %}

{{ imageOwner }} is slimier to echo $imageOwner in php. So you do not need to wrap variable with {{}} when you don't want to print it.

Sign up to request clarification or add additional context in comments.

2 Comments

This is not wrong, but this blatantly lacks of explanations
no it actually works! but I can only accept the answer in a few minutes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.