Skip to content

Instantly share code, notes, and snippets.

@nuryagdym
Created July 2, 2020 14:04
Show Gist options
  • Save nuryagdym/a3705ed8c6c35f914155ab73d8087662 to your computer and use it in GitHub Desktop.
Save nuryagdym/a3705ed8c6c35f914155ab73d8087662 to your computer and use it in GitHub Desktop.
Symfony Form Builder Bootstrap 4 input-group Append and Prepend
{% use "bootstrap_4_layout.html.twig" %}
{# extend form_widget_simple #}
{% block form_widget_simple -%}
{%- if (prepend is defined) or (append is defined) -%}
<div class="input-group{{ group_class|default('') }}">
{%- if prepend is defined -%}
<div class="input-group-prepend">
{{ prepend|raw }} {# without raw filter the html code will be escaped #}
</div>
{%- endif -%}
{{- parent() -}}
{%- if append is defined -%}
<div class="input-group-append">
{{ append|raw }}
</div>
{%- endif -%}
</div>
{%- else -%}
{{- parent() -}}
{%- endif -%}
{%- endblock form_widget_simple %}
{% form_theme form 'my_bootstrap_4_layout.html.twig' %}
{{ form_start(form) }}
{{ form_row(form.facebook, {'prepend': '<button class="btn btn-icon btn-facebook"><i class="fab fa-facebook-f"></i></button>'}) }}
{{ form_row(form.area, {'append': '<span class="input-group-text" id="basic-addon1">m²</span>'}) }}
{{ form_end(form) }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment