Last active
March 17, 2021 16:29
-
-
Save kthalmann/4ba6b3902552c048df13e73a92055f75 to your computer and use it in GitHub Desktop.
Symfony - Render bootstrap 4 input-group (append)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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 %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good point, thx!