Customizing Symfony Form Templates: Difference between revisions
Jump to navigation
Jump to search
(Created page with "Category:Symfony Category:Web Development == Form errors == Form errors are rendered with a `{% form_errors %}` block. Field errors are rendered with a `{% field_er...") |
No edit summary |
||
| Line 9: | Line 9: | ||
=== Global customization === | === Global customization === | ||
Create a stand-along template that overrides the `form_errors` block: | Create a stand-along template that overrides the `form_errors` block:<ref>[http://symfony.com/doc/current/cookbook/form/form_customization.html#making-application-wide-customizations Making Application-Wide Customizations], Symfony Template Cookbook</ref> | ||
<syntaxhighlight lang="twig"> | <syntaxhighlight lang="twig"> | ||
| Line 20: | Line 20: | ||
{% endfor %} | {% endfor %} | ||
</div> | </div> | ||
{% endblock %} | {% endblock %} | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 31: | Line 31: | ||
twig: | twig: | ||
form_themes: | |||
- ':form:errors.html.twig' | |||
</syntaxhighlight> | </syntaxhighlight> | ||
== Notes == | |||
<references /> | |||
Revision as of 15:06, 8 February 2015
Form errors
Form errors are rendered with a {% form_errors %} block.
Field errors are rendered with a {% field_errors %} block.
Global customization
Create a stand-along template that overrides the form_errors block:[1]
{# app/Resources/views/form_theme.html.twig #}
{% block form_errors %}
<div class="alert alert-danger alert-form-errors">
{% for error in errors %}
<div>{{ error.messageTemplate|trans(error.messageParameters, 'validators') }}</div>
{% endfor %}
</div>
{% endblock %}
Update the application configuration:
# app/config/config.yml # ... twig: form_themes: - ':form:errors.html.twig'
Notes
- ↑ Making Application-Wide Customizations, Symfony Template Cookbook