Override Form Field Rendering

geposted am 06.04.2020, in Symfony Twig

Overriding form_error block for all forms here.

{# templates/Form/fields.html.twig #}

{% block form_errors %}
	{% spaceless %}
		{% if errors|length > 0 %}
		<div class="alert alert-danger">
			<ul>
				{% for error in errors %}
					<li>{{ error.message }}</li>
				{% endfor %}
			</ul>
		</div>
		{% endif %}
	{% endspaceless %}
{% endblock form_errors %}

 

Add to form_themes in config/packages/twig.yaml

  form_themes:
    - 'Form/fields.html.twig'