{% macro with_errors(field) %}
  {% if field.errors %}
    {% set css_class = 'invalid ' + kwargs.pop('class', '') %}
    {{ field(class=css_class, **kwargs) }}
    {% if field.description %}<span class="help">{{ field.description|safe() }}</span>{% endif %}
    <ul class="errors">{% for error in field.errors %}<li>{{ error|e }}</li>{% endfor %}</ul>
  {% else %}
    {{ field(**kwargs) }}
    {% if field.description %}<span class="help">{{ field.description|safe() }}</span>{% endif %}
  {% endif %}
{% endmacro %}

{% macro admin_field(field) %}
  <div class="control-group{% if field.errors %} error{% endif %}">
    {{ field.label(class="control-label") }}
    <div class="controls">
      {% set css_class = 'span8 ' + kwargs.pop('class', '') %}
      {% if field.errors %}
        {% set css_class = 'error ' + css_class %}
      {% endif %}
      {{ field(class=css_class, **kwargs) }}
      {% if field.description %}<span class="help-inline">{{ field.description|safe() }}</span>{% endif %}
      {% for error in field.errors %}<span class="help-inline">{{ error|e }}</span>{% endfor %}
    </div>
  </div>
{% endmacro %}
