将变量注入扩展树枝 form_theme [英] Inject variable into extended twig form_theme
问题描述
我要创建一个动态表单,我想扩展一个小部件以将其显示为 I have a dynamic form to create and i want to extend a widget in order to display it as 我想要做的就是像这样迭代 All I want to do is iterate over groups in the 这是表头 这是 myform 块: Here is the myform block : 我得到一个异常 And I get an exception 我找到了一个简单的解决方案. I have found a simple solution. 在我的表单类型文件中,我添加了一个 In my form type file I've added a 现在我可以使用: 这篇关于将变量注入扩展树枝 form_theme的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!.事实上,表格的每一列都是一个包含一些字段的动态组.
<tr>
.
The fact is that each column of the table is a dynamic group containing some fields.myform_widget
中的组:myform_widget
like that :<table id="myforms-table" class="table">
<thead>
<tr>
{% for group in groups %}<th>{{ group.label }}</th>{% endfor %}
</tr>
</thead>
<tbody data-prototype="{{ form_widget(form.myforms.vars.prototype)|e }}">
</tbody>
</table>
{% block myform_widget %}
<tr>
{% for group in groups %}
<td>
{% for field in group.fields %}
{{ form_row( form.children.(field.codeField) ) }}
{% endfor %}
</td>
{% endfor %}
</tr>
{% endblock %}
变量组"不存在
.我假设 form_theme 无法访问 groups
变量,但是我如何才能访问它?强文本谢谢o/Variable "groups" does not exist
.
I assume that the form_theme cannot access to groups
variable, but how can I have access to it ?
strong text
Thanks o/推荐答案
groups
属性,如下所示:groups
attr, like that :public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['groups'] = $this->groups;
}
{% block partition_widget %}
<tr>
{% for group in form.vars.groups %}
<td>
{% for field in group.fields %}
{{ form_row( attribute(form, field.codeField) ) }}
{% endfor %}
</td>
{% endfor %}
</tr>
{% endblock %}
登录
关闭