Skip to content

Instantly share code, notes, and snippets.

@tentacode
Created August 24, 2013 09:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tentacode/6327011 to your computer and use it in GitHub Desktop.
Save tentacode/6327011 to your computer and use it in GitHub Desktop.
Separating regular fields and buttons rendering in a Symfony/Twig form. (from Symfony 2.3)
{% macro form_fields(form) %}
{% for field in form %}
{% if field.vars.block_prefixes[0] != 'button' %}
{{ form_row(field) }}
{% endif %}
{% endfor %}
{% endmacro %}
{% import _self as macros %}
<form class="form-horizontal" method="post" action="{{ path('foo_bar') }}" {{ form_enctype(form) }}>
{{ macros.form_fields(form) }}
<div class="form-actions">
<p>
{{ form_widget(form.submit) }}
</p>
</div>
{{ form_rest(form) }}
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment