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

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -