tags:

views:

38

answers:

2

I have written a form template 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?

+3  A: 

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 %}
Van Gale
Thanks that worked! I have chosen the inclusion tag, which works fine for this use-case.
Tom Tom
+1  A: 

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 %}
Daniel Roseman
Oh that's neat! +1
Van Gale