fabpot/Twig — Issue #487: Exception when using default filter on "non-simple variables"
Author: jmikola
Created: 2011-10-28 17:35:31+00:00
State: open

After the recent changes to the `defined` test and `default` filter, I'm seeing the following exception when Twig parses one of our macro templates:

The "defined" test only works with simple variables in "ExerciseBundle:Frontend\/Includes:macros.html.twig" at line 1

I don't know why the error was reported on "line 1", which was an opening `{% macro %}` tag. I traced the problem down to the middle of this huge 600+ line file:

```jinja
{% if _self.labelClass({'user':user})|default(false) %} foo {% else %} bar {% endif %}
```

The `labelClass` macro is defined as:

```jinja
{% macro labelClass(config) %}{% spaceless %}
{% set label = config.label|default(exercise_userLabel(config.user)) %}
{% if label|default(false) %}
{{ ' ' ~ label|lower ~ ' with_label' }}
{% endif %}
{% endspaceless %}{% endmacro %}
```

My conclusion is that `default(false)` is superfluous for both `if` statements (I didn't write the code :). Still, I think the `default` filter has a legitimate use on these "non-simple variables", which I assume includes returned values from method calls and other macros.