Sirius Sirius - 1 month ago 10
Twig Question

twig if statement with multiple conditions [symfony2]

I have an entity named

verified
in my table
user
. I would like if verified is
null
to show this [you can upload your application], if verified
=2
to show this [your application is in process], if verified
=3
your application has been verified.

but for now if verified
=3
is showing the message of verified
=2.


This is what i have done:

{% if entity.verified is empty %}

<p>
you can upload your application
</p>

{% elseif entity.verified|length !=2 %}

<p>
your application is in process
</p>

{% elseif entity.verified|length !=3 %}

<p>
your application has been verified
</p>
{% endif %}


User.php

/**
*
* @ORM\Column(name="verified", type="decimal", options={"default" : 0}, nullable=true)
*/
protected $verified;

/**
* Set verified
*
* @param string $verified
* @return User
*/
public function setVerified($verified)
{
$this->verified = $verified;

return $this;
}

/**
* Get verified
*
* @return string
*/
public function getVerified()
{
return $this->verified;
}

Answer

You don't need to use the length filter (the scope of that filter is for count the element of an array, collection etc), so try simple:

 {% if entity.verified is empty %}

<p>
you can upload your application
</p>

{% elseif entity.verified ==2 %}

<p>
your application is in process
</p>

{% elseif entity.verified ==3 %}

<p>
your application has been verified
</p>
 {% endif %}

And invert the condition.

Hope this help

Comments