4

私の場合は非常に単純です。

  • テキスト/プレーンメールのテンプレートがあります: body.txt
  • text/html メール用の別のもの: body.html

私は EmailAlternative を使用して両方を同じメールで送信しているため、この 2 つのメールの内容は同じです。

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>

もちろん、翻訳、css、および複数のブロックを使用すると、もう少し複雑になります。

私の願いは、 invitation.txtを定義することです:

{% block message %}Dear {{ first_name|title }} {{ last_name|upper }},

Your inscription has bee accepted. Welcome!
{% endblock %}

(body.txt、invitation.txt) と (body.html、invitation.txt) を読み込んで、2 つの html パーツを取得できるようにしたいと考えています。

編集:

そんな感じ:

招待状/body.txt :

{% extends body.txt invitation.txt %}

招待状/body.html :

{% extends body.html invitation.txt %}
4

2 に答える 2

7

インクルードを使用できます

例: invitation.txt

Dear {{ first_name|title }} {{ last_name|upper }},

Your inscription has bee accepted. Welcome!

招待状/本文.txt :

{% extends body.txt %}
{% block message %}
{% include "invitation.txt" %}
{% endblock %}

招待状/body.html :

{% extends body.html %}
{% block message %}
{% include "invitation.txt" %}
{% endblock %}
于 2013-01-25T14:42:24.927 に答える
6

extendsコンテキストに変数を設定して、テンプレートタグに渡すことができます。

Invitation.txt:

{% extends base %}
{% block message %}Dear {{ first_name|title }} {{ last_name|upper }},

Your inscription has been accepted. Welcome!
{% endblock %}

Invitation.txt を context でレンダリングし{'base': 'body.txt'}、次にcontext でレンダリングします{'base': 'body.html'}

于 2013-01-25T14:47:14.100 に答える