0

I've run up against the limits of includes and macros for the context before me and can't quite get my head round other options such as use and embed, which I've never had need to use before.

I know that a variable established in a parent template, and subsequently altered in a child include, is not available in its updated state to the parent template later:

{% set var = null %}
{% include 'childTemplate' %} {# <-- do something in there with `var` #}
{# back in the parent `var` is still null #}

So I know the following cannot work but it's the essence of what I want to achieve. (Lots of other conditional complexity not shown.)

{# Compose variable content #}
{% set allPeople = {} %}
{% set programme %}
    {% include 'partials/_programmeList' %}

        {# `_programmeList` scope incorporates #}
        {% for item in progItems %}
            {% set personas = item.fieldHandle.all() %}
            {% include 'partials/_progItemPeople' %}

                {# `_progItemPeople` scope incorporates #}
                {% for persona in personas %}
                    {# run a macro that builds finicky `hCard` markup #}
                    {# want to merge `{(persona.id):hCard}` into `allPeople` #} 
                {% endfor %}
        {% endfor %}
{% endset %}

{# Output #}
{% block content %}
    {{ programme|raw }}
    {# want to do something with an updated `allPeople` #}
{% endblock %}

The reason _progItemPeople is a grandchild include is because personas gets set twice within item, once for each of 2 different fieldHandles, and so _progItemPeople gets run twice.

Can use and/or embed help me out with compiling allPeople here? I've done some reading around but haven't managed to join the dots yet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.