I want to be able to populate up variables from included twig templates, just like when you're extending another template. Here's an example:
I have base.twig as follows:
{# base.twig #}
<html>
<head></head>
<body class="body {{class_from_index}}">
<nav>...</nav>
{% block content %}
{% endblock %}
<footer>...</footer>
</body>
</html>
and index.twig as follows:
{# index.twig #}
{% extends "base.twig" %}
{% set class_from_index = 'index' }
{% block content %}
<div>My actual content</div>
{% endblock %}
doing like this, the variable class_from_index is populated to base.twig, when I'm rendering index.twig.
However if i have gallery.twig like this:
{# gallery.twig #}
{% set class_from_index = 'gallery' %}
<div>
A gallery
</div>
and adding {% include gallery.twig %} in index.twig, the variable class_from_index is not populated up to index.twig or base.twig. I know that if gallery.twig extends index.twig and index.twig extends base.twig, this will work, but this is not the case.
Is there a way to achieve what I'm trying to explain? Thank you :)