I had a little but unpleasant problem with symfony2 Field component. For example, I would like to output array of form fields in twig template:
{% for field in form %}
{{ form_label( field ) }}: {{ form_field( field ) }}
{% endfor %}
And here is text field configuration:
$field = new TextField( 'FieldName', array(
'label' => 'MyCustomLabel',
) );
But unfortunately when engine renders this output i get 'FieldName' as label instead of 'MyCustomLabel'. I would not have problems if i outputting form fields not in for (in that case i can just add a label in template for each field). But the script doesn't know certain quantity and configuration of form fields before execution. So, I need to implement cycle method for field rendering. And I also want to stay in twig notation...I will be pleased for a good advise :)
If you want to change the label, than follow the steps.
1) Create form class.
2) add('fieldName',null,array('label' => 'My New Label:'))
please do not change fieldName, but you can play with Label within an array.
Enjoy!
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