开发者

django change label in a included .html form template - e.g. from "Add" to "Save"

I have written a form tem开发者_开发知识库plate to be used in different templates with the include tag.

 {% include "crm/contact_form.html" %}

This form includes a submit button. Now I want to change the label of the button according to the circumstances the form is used.

For example if the form is included in a add template the label should be "Add" and in a detail template the label should be "Save".

How can i accomplish this?


You will either need to put the label into a context variable where it can be used by the contact_form.html template or switch from {% include %} to an inclusion tag which will let you pass arguments like this:

{% load contact_form %}
...
{% contact_form mylabel %}


As an alternative to Van's method, you can set the variable in the enclosing template via with:

{% with "Add" as mylabel %}
  {% include "crm/contact_form.html" %}
{% endwith %}


Since Django 1.3, you can combine the include and with tags

{% include "form_snippet.html" with form=comment_form %}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜