I’m trying to do an if statement with data passed to the twig file from the controller. Below is a line from the controller:
return $this->redirect($this->generateUrl('homepage', array('user' => $user, 'contact' => $contact)));
My goal is to do an if statement with the variable ‘contact’. I checked the twig reference and it shows how to do an if statement but that would not work with ‘contact’. Below is the code I tried, can somebody tell me what I’m doing wrong?
{% if {{ contact.id }} > 0 %}
{{ contact.addrLineOne }}
{% else %}
--
{% endif %}
You’re almost there, just a small syntax modification will make your code working!
In Twig, curly braces means that you want to print the value of a variable or an expression. So you’re statement in PHP would look like this :