如果我在表单中嵌入表单类型Collection。我已将allow_add设置为true。如何覆盖原型输出是可能的。假设我想在每个添加的表格中包装表单类型的集合。想想我可以在jquery中使用原型输出,但更愿意从一开始就做到这一点。例如,我的收藏类型为:
class EmailShareType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add("shareName","text",array("label"=>"Recipient Name:"));
$builder->add("emailName", "email", array("label"=>"Recipient Email:","required" => true));
$builder->add("emailMessage", "textarea",array("label"=>"Enter email message", "max_length" => "4000"));
}
public function getName()
{
return 'emailShare';
}
}
,结果原型呈现为:
data-prototype="
<div>
<label class="required">__name__label__</label>
<div id="emailShareCollection_emailShares___name__">
<div>
<label for="emailShareCollection_emailShares___name___shareName" class="required">Recipient Name:</label>
<input type="text" id="emailShareCollection_emailShares___name___shareName" name="emailShareCollection[emailShares][__name__][shareName]" required="required" />
</div>
<div>
<label for="emailShareCollection_emailShares___name___emailName" class="required">Recipient Email:</label>
<input type="email" id="emailShareCollection_emailShares___name___emailName" name="emailShareCollection[emailShares][__name__][emailName]" required="required" />
</div>
<div>
<label for="emailShareCollection_emailShares___name___emailMessage" class="required">Enter email message</label>
<textarea id="emailShareCollection_emailShares___name___emailMessage" name="emailShareCollection[emailShares][__name__][emailMessage]" required="required" maxlength="4000"></textarea>
</div>
</div>
</div>"
如何控制此输出?
答案 0 :(得分:5)
您可以传递custom template
:
data-prototype="{% filter escape %}{% include 'YourBundle:YourController:yourTemplate.html.twig' with {'form': form.collectonField.get('prototype')} %}{% endfilter %}"