Reputation: 27825
I have this html django template:
{{ header }}
{{ content }}
{{ footer }}
This means the context takes these variables: header, content, footer.
Is there something possible like this:
Template(...).render(
dict(header='foo', content='bar', footer='blu',
content__post='this should be between content and footer')
The needed result:
foo
bar
this should be between content and footer
blu
I don't want to modify all templates to contain content__post
, since there are a lot of templates.
How to "inject" snippets post/pre (below/above) the place of other variables?
Upvotes: 2
Views: 45
Reputation: 1867
Just add the in between content to content
and there you go. This could be done with a context processor, if you want it completely automated.
def add_something(context):
if somecondition_maybe:
context['content'] += "some more content to be added"
return context
and then add your_app.context_processors.add_something
into your template context processors (in settings.py
).
see more: own context processors and context_processors
Upvotes: 2