-
-
Save Cartman34/0beff5649a8eb8c2fdf9c58b96c91320 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_layout.html.twig" %} | |
{# Override form_widget_simple block to render bootstrap input-group with prepend and append #} | |
{% block form_widget_simple -%} | |
{%- if input_prepend is defined or input_append is defined -%} | |
<div class="input-group"> | |
{%- endif -%} | |
{%- if input_prepend is defined -%} | |
<div class="input-group-prepend"> | |
<span class="input-group-text" id="{{ form.vars.id ~ "_prepend" }}">{{ input_prepend | raw }}</span> | |
</div> | |
{%- endif -%} | |
{{- parent() -}} | |
{%- if input_append is defined -%} | |
<div class="input-group-append"> | |
<span class="input-group-text" id="{{ form.vars.id ~ "_append" }}">{{ input_append | raw }}</span> | |
</div> | |
{%- endif -%} | |
{%- if input_prepend is defined or input_append is defined -%} | |
</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_append = 'm²' %} | |
{{ block('form_widget_simple') }} | |
{%- endblock %} | |
{{ form_row(form.path, {'input_prepend': '/home'}) }} | |
{{ form_row(form.end, {'input_prepend': 'to', 'input_append': 'm'}) }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment