SYMFONY 6- TWIG模板中的访问CollectionType字段
我有一个Symfony 6项目,在这里我以一种形式的收藏品。
该系列类型称为“变体”,具有三个字段。让我们打电话给它们:
- field_1
- field_2
- field_3
如果我在twig模板中呈现此collectionType,则使用{{form_row(form.variants)}}
collectionType的所有三个字段均在Neith下渲染。
但是,我想在彼此相邻自己的列中分离收集类型的每个字段。但是我如何访问字段?
我试图通过{{form_row(form.variants.field_1)}}}
访问字段,但显然这不起作用。
我对任何想法感到高兴:)
I have a Symfony 6 project, where I us a CollectionType in a Form.
This CollectionType is called "variants" and has three fields. Lets call them:
- Field_1
- Field_2
- Field_3
If I render this CollectionType in my Twig template with {{form_row(form.variants)}}
all three fields of the CollectionType are rendered underneith.
However, I would like to to separate each of the fields of the CollectionType in a own column next to each other. But how dow I access the fields?
I have tried to access the fields via {{form_row(form.variants.Field_1)}}
but obviously that did not work.
I am happy about any ideas :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你很近。
CollectionType是一个数组 - 因为它可以容纳多组类型。
如果您只有一组,请尝试
使用for方法:
you were close.
CollectionType is an array - as it can hold multiple sets of the type.
If you only have one set try
The for method:
再次感谢Rufinus。
我使用了VinceamStoutz的这些信息和言论,并在Foor循环中进行了创建:
Thanks to Rufinus again.
I used that information and the remark from vinceAmstoutz and did the creation in a foor loop: