{% load wagtailadmin_tags i18n %} {% comment "text/markdown" %} The field template is very flexible to cater for a wide range of use cases. It has two main attributes that support different use cases: 1. `field` to render a Django form field. This may be done through the `{% formattedfield my_field %}` template tag, or a direct `include` of this template. 2. `rendered_field` to render arbitrary HTML. This may be done through the tag pair `{% rawformattedfield %}{% endrawformattedfield %}`, or a direct `include` of this template. If both `field` and `rendered_field` are passed, `rendered_field` will be used as the actual form rendering, but metadata for the surrounding elements (such as help text and ID) will be picked up from `field`. A unified template for both use cases is messy, but it guarantees we are keeping form field styles the same everywhere. {% endcomment %}
{# Render custom label attributes if provided, or the bound field’s label attributes otherwise. #} {% if show_label %} {# Add an id to the label so we can use it as a descriptor for the "Add comment" button. #} {% endif %} {# It’s possible to customize the fields’ layout based on widget type. #} {# Customizing fields based on the field type is only supported for backwards compatibility. #}
{# Always associate a wrapping div with the field, so JS error rendering knows where to put error messages. #}
{% if errors %} {% icon name="warning" classname="w-field__errors-icon" %}

{% for error in errors %}{{ error|escape }} {% endfor %}

{% endif %}
{% if help_text %}
{{ help_text }}
{% endif %}
{# Separate container for the widget with prefix icon and suffix comment button #}
{% if icon %} {% icon name=icon classname="w-field__icon" %} {% endif %} {{ rendered_field }} {% if show_add_comment_button %} {% endif %}