- This makes many places more readable.
- Gives us translation in two places.
- Allows easier changing of labels in a central place.
{{ wtforms_util.render_field_div(form.new_password) }}
<div class="form_field_input">
<p>{{ form.wants_comment_notification }}
- {{ form.wants_comment_notification.label }}</p>
+ {{ wtforms_util.render_label(form.wants_comment_notification) }}</p>
</div>
<div class="form_field_input">
<p>{{ form.license_preference }}
- {{ form.license_preference.label }}</p>
+ {{ wtforms_util.render_label(form.license_preference) }}</p>
</div>
<div class="form_submit_buttons">
<input type="submit" value="{% trans %}Save changes{% endtrans %}" class="button_form" />
<p class="delete_checkbox_box">
{{ form.confirm }}
- <label for="{{ (form.confirm.name) }}">{{ _(form.confirm.label.text) }}</label>
+ {{ wtforms_util.render_label(form.confirm) }}
</p>
<div class="form_submit_buttons">
<p class="delete_checkbox_box">
{{ form.confirm }}
- <label for="{{ (form.confirm.name) }}">{{ _(form.confirm.label.text) }}</label>
+ {{ wtforms_util.render_label(form.confirm) }}
</p>
<div class="form_submit_buttons">
<br />
- <p class="form_field_label">
- <label for="{{ (form.collection.name) }}">{{ _(form.collection.label.text) }}</label>
- </p>
+ {{- wtforms_util.render_label_p(form.collection) }}
<div class="form_field_input">
{{ form.collection }}
<a class="button_action" id="button_addcollection">{% trans %}+{% endtrans %}</a>
<p class="delete_checkbox_box">
{{ form.confirm }}
- <label for="{{ (form.confirm.name) }}">{{ _(form.confirm.label.text) }}</label>
+ {{ wtforms_util.render_label(form.confirm) }}
</p>
<div class="form_submit_buttons">
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#}
+{# Render the label for a field #}
+{% macro render_label(field) %}
+ {%- if field.label.text -%}
+ <label for="{{ field.label.field_id }}">{{ _(field.label.text) }}</label>
+ {%- endif -%}
+{%- endmacro %}
+
+{# Render the label in a <p> for a field #}
+{% macro render_label_p(field) %}
+ {%- if field.label.text %}
+ <p class="form_field_label">
+ {{- render_label(field) -}}
+ </p>
+ {%- endif %}
+{%- endmacro %}
+
{# Generically render a field #}
{% macro render_field_div(field) %}
- {% if field.label.text -%}
- <p class="form_field_label"><label for="{{ field.label.field_id }}">{{ _(field.label.text) }}</label></p>
- {%- endif %}
+ {{- render_label_p(field) }}
<div class="form_field_input">
{{ field }}
{%- if field.errors -%}