Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: pass data back from included/imported templates #1435

Open
NVolcz opened this issue Mar 20, 2023 · 0 comments
Open

Feature request: pass data back from included/imported templates #1435

NVolcz opened this issue Mar 20, 2023 · 0 comments

Comments

@NVolcz
Copy link

NVolcz commented Mar 20, 2023

It is sometimes useful to be able to pass data back from the parent template when dealing with included and/or imported child templates.

My specific use case:

Parent:

{% set footnotes = ["that means that", "the other thing refers to that"] %}
{% set content = "this, that[^1] the other thing[^2]" %}
<section class="content">
{% include "content.njk" %}
</section>
<section class="footnotes">
{% foreach reference in references %}
<div>{{ footnotes[reference - 1] }}</div>
{% endfor %}
</section>

Child (content.njk):

{# I have some complex macro here to render the content which finds and formats references #}
{% set references = [1,2] %}
{{ content | markdown }}

Would be nice if there were a {% include "content.njk" allow-writing-to-context %} or some other way to allow a child template to pass data back through the context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant