Skip to content

Instantly share code, notes, and snippets.

@teisman
Last active March 1, 2018 22:09
Show Gist options
  • Save teisman/5653607 to your computer and use it in GitHub Desktop.
Save teisman/5653607 to your computer and use it in GitHub Desktop.
{% macro render(form) -%}
<fieldset>
{% for field in form %}
{% if field.type in ['CSRFTokenField', 'HiddenField'] %}
{{ field() }}
{% else %}
<div class="clearfix {% if field.errors %}error{% endif %}">
{{ field.label }}
<div class="input">
{% if field.name == "body" %}
{{ field(rows=10, cols=40) }}
{% else %}
{{ field() }}
{% endif %}
{% if field.errors or field.help_text %}
<span class="help-inline">
{% if field.errors %}
{{ field.errors|join(' ') }}
{% else %}
{{ field.help_text }}
{% endif %}
</span>
{% endif %}
</div>
</div>
{% endif %}
{% endfor %}
</fieldset>
{% endmacro %}
{% import '_forms.html' as forms %}
<!-- ... -->
{% block form %}
<section>
<h1>{{ action }} {{ data_type }}</h1>
<form action="{{ form_action }}" method="{{ method | d("POST") }}">
{{ forms.render(form) }}
<input type="submit" value="Submit">
</form>
</section>
{% endblock form %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment