-
-
Save nuryagdym/ab84944f5c275758c8cdf090fd8bf18e to your computer and use it in GitHub Desktop.
Symfony 4 bootstrap 4 check box form label with link
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
{% form_theme form _self %} | |
{% block checkbox_radio_label -%} | |
{# {% block _user_registration_form_termsAccepted_label %} - use this if you need it for just a single field, amend accordingly to your form type/field #} | |
{#- Do not display the label if widget is not defined in order to prevent double label rendering -#} | |
{%- if widget is defined -%} | |
{% set is_parent_custom = parent_label_class is defined and ('checkbox-custom' in parent_label_class or 'radio-custom' in parent_label_class) %} | |
{% set is_custom = label_attr.class is defined and ('checkbox-custom' in label_attr.class or 'radio-custom' in label_attr.class) %} | |
{%- if is_parent_custom or is_custom -%} | |
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' custom-control-label')|trim}) -%} | |
{%- else %} | |
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' form-check-label')|trim}) -%} | |
{%- endif %} | |
{%- if not compound -%} | |
{% set label_attr = label_attr|merge({'for': id}) %} | |
{%- endif -%} | |
{%- if required -%} | |
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) -%} | |
{%- endif -%} | |
{%- if parent_label_class is defined -%} | |
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ parent_label_class)|replace({'checkbox-inline': '', 'radio-inline': '', 'checkbox-custom': '', 'radio-custom': ''})|trim}) -%} | |
{%- endif -%} | |
{%- if label is not same as(false) and label is empty -%} | |
{%- if label_format is not empty -%} | |
{%- set label = label_format|replace({ | |
'%name%': name, | |
'%id%': id, | |
}) -%} | |
{%- else -%} | |
{%- set label = name|humanize -%} | |
{%- endif -%} | |
{%- endif -%} | |
{{ widget|raw }} | |
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}> | |
{{- label is not same as(false) ? (translation_domain is same as(false) ? label : label|trans({}, translation_domain))|raw -}} | |
{{- form_errors(form) -}} | |
</label> | |
{%- endif -%} | |
{%- endblock checkbox_radio_label %} | |
... | |
{{ form_row(form.termsAccepted) }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment