Skip to content

Instantly share code, notes, and snippets.

@kthalmann
Last active March 17, 2021 16:29
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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 %}
@redstar504
Copy link

redstar504 commented Mar 13, 2019

Works great if you change {% set input_group_addon = 'm²' %} to {% set input_addon = 'm²' %} in the custom widget block.

@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