{% macro hint(field) %}
  {%- if field.hint and not field.widget.renders_hint %}
    <p class="hint">{{ field.hint }}</p>
  {%- endif -%}
{% endmacro -%}

{% macro label(field, changed) %}
  {%- if field.label %}
    <label for="{{ field.id }}"
           {%- if changed %} title="Имеются изменения по сравнению с опубликованной версией"{% endif %}>
      {{ field.label }}
    </label>
  {%- endif -%}
{% endmacro -%}

{% macro help(field) %}
  {%- if field.help_message %}
    <div class="help-message hide">{{ field.help_message }}</div>
  {%- endif -%}
{% endmacro -%}

{% for field in form.fields %}
  {%- set widget=field.widget -%}
  {%- set changed = field.form.changed_fields is defined and 
                    field.input_name in field.form.changed_fields %}
  {% if field.readable %}
    <div class="form-row
                {%- if changed %} changed-after-publication{% endif %}
                {%- if field.error %} with-error{% endif %}
                {%- if widget.render_type == 'full-width' %} full-width{% endif %}"
          {%- if widget.render_type == 'hidden' %} style="display: none"{% endif %}>
        {% if field.error %}
          <div class="error">{{ field.error }}</div>
        {% endif %}
    
        {%- if widget.render_type == 'checkbox' %}
          {{- widget.render()|safe }}
          {{- label(field, changed) }}
          {{- hint(field) -}}
          {{- help(field) -}}
        {%- elif widget.render_type == 'hidden' %}
          {{- widget.render()|safe }}
        {%- elif widget.render_type == 'full-width' %}
          {{- help(field) -}}
          {{- label(field, changed) }}
          {{- widget.render()|safe }}
          {{- hint(field) -}}
        {% else %}
          {%- if field.label or field.help_message -%}
            <div class="form-label">
                {{- label(field, changed) -}}
            </div>
          {%- endif -%}
          {{ widget.render()|safe }}
          {{- hint(field) -}}
          {{- help(field) -}}
        {% endif -%}
    </div>
  {%- endif %}
{%- endfor %}
