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.
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 %}