Skip to content

Instantly share code, notes, and snippets.

@kthalmann
Last active March 17, 2021 16:29
Show Gist options
  • Save kthalmann/4ba6b3902552c048df13e73a92055f75 to your computer and use it in GitHub Desktop.
Save kthalmann/4ba6b3902552c048df13e73a92055f75 to your computer and use it in GitHub Desktop.
Symfony - Render bootstrap 4 input-group (append)
{% use "bootstrap_4_horizontal_layout.html.twig" %}
{# Override form_widget_simple block to render bootstrap input-groups #}
{% block form_widget_simple -%}
{%- if input_addon is defined -%}
{% set aria_describedby = 'addon-' ~ random() %}
{%- set attr = attr|merge({'aria-describedby': aria_describedby}) -%}
<div class="input-group">
{%- endif -%}
{{- parent() -}}
{%- if input_addon is defined -%}
<div class="input-group-append">
<span class="input-group-text" id="{{ aria_describedby }}">{{ input_addon }}</span>
</div>
</div>
{%- endif -%}
{%- endblock form_widget_simple %}
{# Example of using an input-group with «m²» addon for a specific form field #}
{% block _project_facadeArea_widget -%}
{% set input_addon = 'm²' %}
{{ block('form_widget_simple') }}
{%- endblock %}
@kthalmann
Copy link
Author

Good point, thx!

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