I have a layout template:
{% set bodyClass = [] %}
<body class="{% for class in bodyClass %}{{ class }} {% endfor %}">
{{ block('pageBody') }}
</body>
And a template that extends it:
{% extends 'layout' %}
{% set bodyClass = bodyClass|merge(['myclass']) %}
{% block pageBody %}
<h1>Hello World</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab, consequuntur!</p>
{% endblock %}
When I try to append to the bodyClass
variable I get the error:
Variable "bodyClass" does not exist.
However if I call the variable:
{% for class in bodyClass %}
{{ class }}
{% endfor %}
The template renders fine. Why can't I merge onto a variable that's been set in an extended template? Is there another way to do this?