Django Multiple template inheritance
django, django-templates, jinja2, templates
Solution
You can set a variable in the context and pass it to `extends` template tag.
In invitation.txt:
{% extends base %}
{% block message %}Dear {{ first_name|title }} {{ last_name|upper }},
Your inscription has been accepted. Welcome!
{% endblock %}
Render invitation.txt with context `{'base': 'body.txt'}`, then with context `{'base': 'body.html'}`.
Problem
My case is quite simple: - I have a template for text/plain mails : body.txt - Another one for text/html mails : body.html The content of this two mail are the same because I use EmailAlternative to send both in the same mail. body.txt: ``` {% block message %}{% endblock %} {{ site_name }} team ----------------- If you need help contact use at {{ support_mail }} ``` body.html: ``` <html> <head> <title>{% block title %}{% endblock %}</title> </head> <body> <p>{% filter linebreaksbr %}{% block message %}{% endblock %}{% endfilter %}</p> <p><strong>{{ site_name }} team</strong></p> <hr/> If you need help contact use at <a href="mailto:{{ support_mail }}">{{ support_mail }}</a> </body> </html> ``` Of course it is a little bit more complex with translation, css and more than one block. My wish is to define invitation.txt: ``` {% block message %}Dear {{ first_name|title }} {{ last_name|upper }}, Your inscription has bee accepted. Welcome! {% endblock %} ``` I want to be able to load (body.txt, invitation.txt) and also (body.html, invitation.txt) to get my two html parts. Edit: Something like that: invitation/body.txt: ``` {% extends body.txt invitation.txt %} ``` invitation/body.html: ``` {% extends body.html invitation.txt %} ```