Skip to content

Instantly share code, notes, and snippets.

@marijn
Created November 23, 2012 21:54
Show Gist options
  • Save marijn/4137467 to your computer and use it in GitHub Desktop.
Save marijn/4137467 to your computer and use it in GitHub Desktop.
This is how you add a link to a label with Symfony forms, sort of. Cause you'll have a label tag twice...
{% set terms_link %}<a title="{% trans %}Read the General Terms and Conditions{% endtrans %}" href="{{ path('get_general_terms_and_conditions') }}">{% trans %}General Terms and Conditions{% endtrans %}</a>{% endset %}
{% set general_terms_and_conditions %}{{ 'I have read and accept the %general_terms_and_conditions%.'|trans({ '%general_terms_and_conditions%': terms_link })|raw }}{% endset %}
<div>
{{ form_errors(form.acceptGeneralTermsAndConditions) }}
{{ form_widget(form.acceptGeneralTermsAndConditions) }}
<label for="{{ form.acceptGeneralTermsAndConditions.vars.id }}">{{ general_terms_and_conditions|raw }}</label>
</div>
@marijn
Copy link
Author

marijn commented Nov 23, 2012

Suggestions are welcome @webmozart 😉

@ThePeterMick
Copy link

@marijn thanks for sharing this, Mr Google took me here 6 years later, for anyone else looking how to achieve in the current symfony4 and bootstrap4 the label is now rendered from within the form_widget call, overriding the form_label appears to be buggy at the moment: symfony/symfony#28823

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment