82171/how-to-access-class-constants-in-twig
I have a few class constants in my entity class, e.g.:
class Entity { const TYPE_PERSON = 0; const TYPE_COMPANY = 1; }
In normal PHP I often do if($var == Entity::TYPE_PERSON) and I would like to do this kind of things in Twig. Is it possible?
Hello @kartik,
Try this:
{% if var == constant('Namespace\\Entity::TYPE_PERSON') %} {# or #} {% if var is constant('Namespace\\Entity::TYPE_PERSON') %}
Hope it is helpfull!!
Thank You!!
Hello @kartik, It is not working because you have to ...READ MORE
Hello @kartik, You can do it with {{ form_widget(formView._token) ...READ MORE
How can I return a variable value ...READ MORE
Hello, Considering that you have $replaced = array('1' => ...READ MORE
Hey @kartik, First you have to go to ...READ MORE
Named route is used to give specific ...READ MORE
Hello, This is simple you just need to ...READ MORE
Hey @kartik, Named routing is another amazing feature of ...READ MORE
Hello @kartik, Using property_exists( mixed $class , string $property ...READ MORE
Hello @kartik, Since PHP 5.4 it's possible to ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.