{% load i18n sniplates %}
Default, basic form rendering

# Built in fields:

    'CharField',
    'IntegerField',
    'DateField',
    'TimeField',
    'DateTimeField',
    'TimeField',
    'RegexField',
    'EmailField',
    'FileField',
    'ImageField',
    'URLField',
    'BooleanField',
    'NullBooleanField',
    'ChoiceField',
    'MultipleChoiceField',
    'ComboField',
    'MultiValueField',
    'FloatField',
    'DecimalField',
    'SplitDateTimeField',
    'IPAddressField',
    'GenericIPAddressField',
    'FilePathField',
    'SlugField',
    'TypedChoiceField',
    'TypedMultipleChoiceField'

# Built in widgets:

    'TextInput',
    'EmailInput',
    'URLInput',
    'NumberInput',
    'PasswordInput',
    'HiddenInput',
    'MultipleHiddenInput',
    'ClearableFileInput',
    'FileInput',
    'DateInput',
    'DateTimeInput',
    'TimeInput',
    'Textarea',
    'CheckboxInput',
    'Select',
    'NullBooleanSelect',
    'SelectMultiple',
    'RadioSelect',
    'CheckboxSelectMultiple',
    'SplitDateTimeWidget',
    'SplitHiddenDateTimeWidget',

How to render labels
{% block _label %}
{% if label %}<label for="{{ id_for_label }}">{{ label }}</label>{% endif %}
{% endblock %}

How to render help_text
{% block _help %}
{{ help_text }}
{% endblock %}

How to render errors
{% block _errors %}
{% if errors %}
<ul class="errorlist">
{% for error in errors %}
    <li class="error">{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
{% endblock %}

{% block input %}
{% with input_type=input_type|default:"text" %}
<input type="{{ input_type }}"
    name="{{ html_name }}"
    id="{{ id }}"
    value="{{ raw_value|default:"" }}"
    class="{{ css_classes }} {{ errors|yesno:"error," }}"
    {{ widget.attrs|flatattrs }}
    {{ required|yesno:"required," }}
    {% if placeholder %}placeholder="{{ placeholder }}"{% endif %}
>
{% endwith %}
{% endblock %}

{% block TextInput %}{% reuse "input" %}{% endblock %}
{% block EmailInput %}{% reuse "input" input_type="email" %}{% endblock %}
{% block NumberInput %}{% reuse "input" input_type="number" %}{% endblock %}
{% block URLInput %}{% reuse "input" input_type="url" %}{% endblock %}
{% block PasswordInput %}{% reuse "input" input_type="password" raw_value="" %}{% endblock %}
{% block HiddenInput %}{% reuse "input" input_type="hidden" label="" %}{% endblock %}
{% block FileInput %}{% reuse "input" input_type="file" value="" %}{% endblock %}
{% block DateInput %}{% reuse "input" input_type="text" raw_value=value %}{% endblock %}
{% block DateTimeInput %}{% reuse "input" input_type="text" raw_value=value %}{% endblock %}
{% block TimeInput %}{% reuse "input" input_type="text" raw_value=value %}{% endblock %}

{% block ClearableFileInput %}
{% if raw_value %}
    {% trans "Currently" %}: <a href="{{ url }}">{{ url }}</a>
    <input type="checkbox" name="{{ html_name }}-clear" id="{{ html_name }}-clear_id">
    <label for="{{ html_name }}-clear_id">{% trans "Clear" %}</label><br>
    {% trans "Change" %}:
{% endif %}
{% reuse "input" input_type="file" raw_value="" %}
{% endblock %}

TODO:

{% block SplitDateTimeWidget %}{% endblock %}
{% block SplitHiddenDateTimeWidget %}{% endblock %}

Fields not derived from InputField:

{% block MultipleHiddenInput %}
{% for value in raw_value %}
<input type="hidden" name="{{ html_name }}" id="{{ id }}_{{ forloop.counter0 }}" value="{{ value|default:'' }}" {{ widget.attrs|flatattrs }} {{ required|yesno:"required," }}>
{% endfor %}
{% endblock %}

{% block Textarea %}
<textarea name="{{ html_name }}" id="{{ id }}"
    class="{{ css_classes }} {{ errors|yesno:"error," }}"
    {{ required|yesno:"required," }}
    {% if placeholder %}placeholder="{{ placeholder }}"{% endif %}
    {{ widget.attrs|flatattrs }}
>{{ raw_value|default:'' }}</textarea>
{% endblock %}


Underscore prefixed to avoid potentially clashing with:
 - {field}_{name}
 - {widget}_{name}
 - {field}_{widget}
{% block _Select_Option %}
<option value="{{ val }}" {% if val == value|default:None %}selected{% endif %}>{{ display }}</option>
{% endblock %}

{% block Select %}
<select name="{{ html_name }}" id="{{ id }}" {{ widget.attrs|flatattrs }}>
{% for choice in choices %}
    {% if choice.is_group %}
    <optgroup label="{{ choice.value }}">
        {% for val, display in choice.display %}
            {% reuse '_Select_Option' val=val value=value display=display %}
        {% endfor %}
    </optgroup>
    {% else %}
        {% reuse '_Select_Option' val=choice.value value=value display=choice.display %}
    {% endif %}
{% endfor %}
</select>
{% endblock %}

{% block SelectMultiple %}
<select name="{{ html_name }}" id="{{ id }}" {{ widget.attrs|flatattrs }} multiple>
{% for val, display in choices %}
    <option value="{{ val }}" {% if val in value %}selected{% endif %}>{{ display }}</option>
{% endfor %}
</select>
{% endblock %}
{% block NullBooleanSelect %}{% reuse "Select" %}{% endblock %}

Checkbox is a special case and needs its own template.
{% block CheckboxInput %}
<label for="{{ form_field.id_for_label }}" class="{{ css_classes }}">
    <input name="{{ html_name }}" id="{{ id }}" type="checkbox" {{ form_field.value|yesno:'checked,' }}>
    {{ form_field.label }}
</label>
{% endblock %}

{% block RadioSelect %}
<ul id="{{ id }}">
{% for val, display in choices %}
    <li><input name="{{ html_name }}" type="radio" id="{{ id}}_{{ forloop.counter0 }}" value="{{ val }}" {% if val == value|default:"" %}checked{% endif %}>{{ display }}</li>
{% endfor %}
</ul>
{% endblock %}

{% block CheckboxSelectMultiple %}
<ul id="{{ id }}">
{% for val, display in choices %}
    <li><input name="{{ html_name }}" type="checkbox" id="{{ id}}_{{ forloop.counter0 }}" value="{{ val }}" {% if val in value %}checked{% endif %}>{{ display }}</li>
{% endfor %}
</ul>
{% endblock %}
