1

Under the default Symfony layout, I can use the first argument on form_label to set the label text for my checkbox. For example, this:

{{ form_label(form.fooCheckbox, 'Foo') }}

Correctly renders as:

<label>Foo</label>

However if I use the Bootstrap layout, this same argument is ignored:

{{ form_label(form.fooCheckbox, 'Foo') }}

Renders as:

<label>*default humanized label*</label>

How can I fix this?

1 Answer 1

3

Just figured this out after taking another look at the Bootstrap layout file. Instead of rendering my checkboxes like this:

{{ form_widget(form.fooCheckbox) }}
{{ form_label(form.fooCheckbox, 'Foo') }}

The label argument has to move up onto the widget, like this:

{{ form_widget(form.fooCheckbox, {'label': 'Foo'}) }}

I can't spot any mention of this in the documentation - hopefully this will help someone else out.

Sign up to request clarification or add additional context in comments.

8 Comments

@Artamiel To clarify, form_label arguments uniquely don't work under the Bootstrap layout. I can't see any mention of this in the link you posted.
You sure? I've included in config - bootstrap_3_layout.html.twig and then in my template file I've modified form_label to {{ form_label(form.email, 'Changed label with bootstrap layout') }} and it displays Changed label with bootstrap layout just fine.
@Artamiel That's odd - can I see the rendered HTML for your label and input?
Since I used form_label and form_widget there is not form-group surrounding div. <label class="control-label required" for="myform_email">Changed label with bootstrap layout</label> for the label and <input type="email" id="myform_email" name="myform[email]" required="required" class="form-control" /> for the input
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.