[英]I am trying to work with Django CMS and templates. but get an error while editing a template
[英]Django templates. I get in my mail parameters, how can I send them to another html with include?
這是我的歡迎容器:
<tr>
<td align="center">
<!-- Start internal container -->
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td height="30" style="line-height:30px; font-size:30px;"> </td>
</tr>
<tr>
<td align="left" style="font-family: 'Lato', sans-serif; font-size:20px; line-height:26px;">
<p style="font-family: 'Lato', sans-serif; margin: 0; padding: 15px 60px 15px 60px; font-weight: bold; color: #333333;">
{{ title }}
</p>
<p style="font-family: 'Lato', sans-serif; font-size:16px; margin: 0; padding: 0px 60px 0px 60px; color: #333333;">
{{ subtitle }}
</p>
</td>
</tr>
</table>
<!-- End internal container -->
</td>
我嘗試了這個:
{% "Hi {{first_name}}" as titleStr%}
{% with title=titleStr subtitle="Please confirm your email address by clicking this button." %}
{% include "emails/_parts/welcome_container.html" %}
{% endwith %}
但是我得到這個問題:
Invalid block tag on line 29: '"Hi', expected 'endblock'. Did you forget to register or load this tag?
我究竟做錯了什么? 第29行是title = titleStr
您寫{% "Hi
和django模板知道這是塊標記的開始。如果只想顯示文本,請將其更改為"Hi {{first_name}}"
如果要通過include傳遞變量,請嘗試以下操作:
{% include "emails/_parts/welcome_container.html" with title={{first_name}} %}
包含文檔https://docs.djangoproject.com/en/2.1/ref/templates/builtins/#include
您已經在模板中添加了{% "Hi" %}
,其中django將“ Hi”視為模板標簽,但在django中不存在,因此這會引發錯誤。 您可能希望在標題變量前面添加Hello,並將其傳遞給另一個模板。 您可以通過add
模板標簽來實現。
{% with "Hello "|add:first_name as titleStr %}
{% include 'emails/_parts/welcome_container.html' with title=titleStr subtitle="Please confirm your email address by clicking this button." %}
{% endwith %}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.