Logical logic does not work as I expect in a branch

{{ dump(extend) }} 

Result:

  boolean false 

And when I want to do this:

 {% if extend is true %} {% extends 'WelcomePageBundle:Default:welcome_page.html.twig' %} {% endif %} 

This does not work. Why?

Error:

 The test "false" does not exist in FOSUserBundle:ChangePassword:changePassword.html.twig at line 1 
+4
source share
2 answers

It should be either {% if extend %} - because extend already logical - or {% if extend == true %} . is used for tests ; not for comparison.

+7
source

You need to use empty test:

Check for empty checks if the variable is empty (null, false, empty array or empty string).

 {% if extend is not empty %} ... {% endif %} 

Take a look at the list of available tests , as well as the logic of the operators from the official Twig documentation.

+4
source

All Articles