I want to render only one field of a form. When i put {{form_end(form)}}
every other field are coming (symfony doc show it clearly) but how to render only one field ? If i dont put {{form_end(form)}}
, there is only one field, but no save button
thanks
Yes, CSS can do the trick. But do you want the working of your application to depend on client side styling rules? In most cases it might beter not to render the field HTML at all.
There are two ways in which you can fix this in your template.
Put {% do form.field_you_want_to_hide.setRendered %}
before your {{form_end(form)}}
.
This will mark the field as rendered and thus it will not show up when form_rest is called.
Instead of {{form_end(form)}}
, use {{ form_end(form, {'render_rest': false}) }}
, as explained in the Symfony Twig documentation.
It would be even better to change your form class such that the fields are removed from your form. Is it your own form you would like to render, or a form from a third party bundle?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With