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 - How to fix Circular Reference

Не загружается Linux (crash)

How to logout from Zoho Desk via SAML