Skip to content

Instantly share code, notes, and snippets.

@weaverryan
Created April 13, 2012 11:26
Show Gist options
  • Save weaverryan/2376058 to your computer and use it in GitHub Desktop.
Save weaverryan/2376058 to your computer and use it in GitHub Desktop.
Some basic Twitter Bootstrap Symfony2 form customizations
{# for twitter bootstrap specifically #}
{% block field_row %}
{% spaceless %}
<div class="control-group {% if errors|length > 0 %}error{% endif %}">
{{ form_label(form, label|default(null)) }}
<div class="controls">
{{ form_widget(form) }}
{{ form_errors(form)}}
</div>
</div>
{% endspaceless %}
{% endblock field_row %}
{% block field_errors %}
{% spaceless %}
{% if errors|length > 0 %}
{% for error in errors %}
<div class="help-inline">
{{ error.messageTemplate|trans(error.messageParameters, 'validators') }}
</div>
{% endfor %}
{% endif %}
{% endspaceless %}
{% endblock field_errors %}
{# special errors block for form errors - at the top of the form, for example #}
{% block form_errors %}
{% spaceless %}
{% if errors|length > 0 %}
<div class="alert alert-error" style="display: inline-block;">
{% for error in errors %}
{{ error.messageTemplate|trans(error.messageParameters, 'validators') }}
<br/>
{% endfor %}
</div>
{% endif %}
{% endspaceless %}
{% endblock form_errors %}
{% block generic_label %}
{% set attr = attr|merge({'class': ''}) %}
{% spaceless %}
{% if required %}
{% set attr = attr|merge({'class': 'required'}) %}
{% endif %}
<label{% for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}"{% endfor %}>{{ label|trans }}</label>
{% endspaceless %}
{% endblock %}
{# end twitter bootstrap stuff #}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment