-
Notifications
You must be signed in to change notification settings - Fork 207
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: provide different data context for included template #221
Comments
I've found Twig to handle this in a very elegant and idiomatic manner:
{# template.html will have access to the variables from the current context and the additional ones provided #}
{% include 'template.html' with {'foo': 'bar'} %}
{% set vars = {'foo': 'bar'} %}
{% include 'template.html' with vars %} You can disable access to the context by appending the only keyword: {# only the foo variable will be accessible #}
{% include 'template.html' with {'foo': 'bar'} only %}
{# no variables will be accessible #}
{% include 'template.html' only %} I don't know how doable it is, and it's perhaps best to stay close to Jinja. Just 2 cents, because the |
Hey @MaxandreOgeret, the reason why I closed this ticket is that my job no longer required a solution based on the template engine and from what I learned from the source code, it may require a lot of effort to bring in this context into inja. And eventually I was sticking with my ~300-line template and the performance of inja is bearable in my solution. I agree with you that this is a nice-to-have feature for inja, so I'm reopening it... |
Problem I'm Trying To Solve
I'd like to pass a variable as the data context of the included template, so a huge template can be split into more modularized sub-templates.
Current Solution
I can only have a huge template with complicated JSON as the only data context.
Requested Solution
It would be very convenient if I could have the following:
in which
"namespace-template"
refers to the sub-template which handles the namespace only, and:namespace
is the provided data context, so don't have to nest loops/conditions in a single template.The text was updated successfully, but these errors were encountered: