well, if you use a form prototype in symfony2, you can not custmize his presentation like you usually do, like some template file. Except you write a customize form type to render your form.
This is a trick:
This is a trick:
This was bugging me too. I customized a field type and even made simple form types with a reduced fieldset (for more complex objects), but it just didn't feel right. I've come up with a solution that should do the trick :)
First - I think your
should be outside your loop.
Next, your prototype is just a form view object, so if you pass it to a template you can render fields by hand and customize the output. Note: autoescape has no effect on included content, so use 'filter escape'.
id="playerFields" data-prototype="{% filter escape %}{% include 'AcmeTeamBundle:Team:prototypePlayer.html.twig' with {'form': form.players.get('prototype')} %}{% endfilter %}">
Then in your prototypePlayer.html.twig, just render each field as you normally would in a form view.
class="title">{{ form_label(form.name) }}
{{ form_row(form.name) }}
class="age">{{ form_label(form.age) }}
{{ form_row(form.age) }}
{# render whatever else you like from your Form/PlayerType class... #}
My template has a different data structure to your question, but it should help :)
评论
发表评论