Symfony - Twig - How to check on instanceof class object

In Twig exist "constant" function that returns constant value, but if you set "class" in first parameter and object in second parameter, then function returns the fully qualified class name of an object. 

So we can use it in our case and compare it on class name that we want to check like "instanceof".

Example:

{% if constant('class', app.user) == 'User' %}{% endif %}

Or with namespace:

{% if constant('class', app.user) == 'EntityBundle\\Entity\\User' %}{% endif %}

Comments

Popular posts from this blog

Symfony - Doctrine - How to change old attributes in entity to new PHP 8 attributes

Symfony - Doctrine - How to save SQL query to Session