symfony - Inject variable into extended twig form_theme -
i have dynamic form create , want extend widget in order display <tr>
. fact each column of table dynamic group containing fields.
all want iterate on groups in myform_widget
:
here table header
<table id="myforms-table" class="table"> <thead> <tr> {% group in groups %}<th>{{ group.label }}</th>{% endfor %} </tr> </thead> <tbody data-prototype="{{ form_widget(form.myforms.vars.prototype)|e }}"> </tbody> </table>
here myform block :
{% block myform_widget %} <tr> {% group in groups %} <td> {% field in group.fields %} {{ form_row( form.children.(field.codefield) ) }} {% endfor %} </td> {% endfor %} </tr> {% endblock %}
and exception variable "groups" not exist
. assume form_theme cannot access groups
variable, how can have access ? strong text o/
i have found simple solution.
in form type file i've added groups
attr, :
public function buildview(formview $view, forminterface $form, array $options) { $view->vars['groups'] = $this->groups; }
now i'm able retrieve :
{% block partition_widget %} <tr> {% group in form.vars.groups %} <td> {% field in group.fields %} {{ form_row( attribute(form, field.codefield) ) }} {% endfor %} </td> {% endfor %} </tr> {% endblock %}
Comments
Post a Comment