twig - How to concatenate a field in a form with a var in Twig?
问题描述
I'm trying to work with a loop in a Controller (in Symfony4) to create a form, with different lines
for ($i=1 ; $i<=$nblig ; $i++)
{
$formBuilder ->add('date'.$i, DateType::class)
-> (...)
}
The form works fine (I can dump it). I need a similar loop, when I try to render that form with Twig :
{% for i in 1..nblig %}
{{ form_widget(form.date ~ i)) }}{% endfor %}
And I don't know how to concatenate the field name date, with the var i.
Thanks for your help
解决方案
您现在正在组合form.date
with的值i
,您想要什么,您可以使用数组表示法或使用attribute
for
{{ form_widget(form['date' ~ i]) }}
{{ form_widget(attribute(form, 'date'~i)) }}
推荐阅读
- r - R:按年份创建具有最高值的表
- python - 在python中将文件保存到Windows路径
- oop - UML 中的多态性和泛化
- html - SVG:FF 和 Chrome 中的文本居中不同
- go - 如何从golang中的对象时间获取字符串或int64?
- c# - 如何从数据库上下文中制作参数以在函数中使用它?
- c# - 如何使用 RDotNet 从 VS 2017 中的 C# 项目访问 R 项目 (RTVS)?
- r - 如何连接条形图,就像 geom_density_ridges 对直方图所做的那样
- excel - 基于特定单元格值从主列表创建子列表,在 Excel 中没有空白行
- docker - 厨师厨房测试失败,但当地考试证明并非如此