I usually load and prepare data before calling a certain include. That data may be loaded in a certain way for different cases, so I cannot add that data preparation code into the include itself. I have to do it before calling it. Like:
{# Example #}
{% set whatever = entry.whatever.one() %}
{% if whatever %}
{% include '/_includes/whatever' with {
'whatever': whatever
} %}
{% endif %}
Of course there will be more complex situations, this is just an example.
If I move the {% set whatever = entry.whatever.one() %}
line into its own include and then do:
{# Example #}
{% include '/_includes/prepare-whatever' %}
{% if whatever %}
{% include '/_includes/whatever' with {
'whatever': whatever
} %}
{% endif %}
The scope stays inside the include, so whatever
is not defined when I need it.
How can I achieve the same functionality, to stay DRY?
Thanks!