Skip to content

Instantly share code, notes, and snippets.

@felixprojekt
Last active July 18, 2020 07:43
Show Gist options
  • Save felixprojekt/ea74cb323a0b0f0b4385008d75485a12 to your computer and use it in GitHub Desktop.
Save felixprojekt/ea74cb323a0b0f0b4385008d75485a12 to your computer and use it in GitHub Desktop.
Add form field ID to form-group element in Symfony 4 bootstrap theme
{% use "bootstrap_4_layout.html.twig" %}
{% block form_row -%}
{%- if compound is defined and compound -%}
{%- set element = 'fieldset' -%}
{%- endif -%}
{%- set widget_attr = {} -%}
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- endif -%}
<{{ element|default('div') }}{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' form-group ' ~ id ~ '-group')|trim})} %}{{ block('attributes') }}{% endwith %}>
{{- form_label(form) -}}{{- form_help(form) -}}
{{- form_widget(form, widget_attr) -}}
</{{ element|default('div') }}>
{%- endblock form_row %}
@felixprojekt
Copy link
Author

Add to twig.yaml

twig:
      .....
      form_themes: ['form/custom_types.html.twig']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment