Check if the variable is defined in symfony twig
In twig, specially for the templates being used by many controllers, there might be variables set by one controller but not by others.
Well one way to address could be to have dummy data on each controller and either to check for that dummy value and do something or just to print it
But, symfony has a way to check if the variable has made it to the template or not
{% if some.variable is defined %} what a world {% endif %}
so the usage of defined can rescue us.
Deploying Symfony app on micro instance of aws – Amazon EC2
{% javascript could not be added in symfony assetic
Fatal error: require(): Failed opening required Hydrator in mongodb
bundle does not contain any mapped documents/entities
the requested PHP extension mongo is missing from your system.
Maltronic
defined is a fine solution, although for reference the default() filter can also be used:
{{ some.variable|default(“”) }}
or in the case of an if statement:
{% if some.variable|default(false) %}Only display if some.variable is set and returns true{% endif %}