Templates Sonata管理包-表单类型:Sonata_类型_集合-自定义模板?
是否可以覆盖表单类型的模板:“sonata_type_集合” 我试过这样做:Templates Sonata管理包-表单类型:Sonata_类型_集合-自定义模板?,templates,symfony,symfony-sonata,sonata-admin,Templates,Symfony,Symfony Sonata,Sonata Admin,是否可以覆盖表单类型的模板:“sonata_type_集合” 我试过这样做: $formMapper->add('slides', 'sonata_type_collection', array(), array( 'edit' => 'inline', 'inline' => 'table', 'sortable' => 'priority',
$formMapper->add('slides', 'sonata_type_collection', array(), array(
'edit' => 'inline',
'inline' => 'table',
'sortable' => 'priority',
'template' => 'MyBundle:Form:slides.admin.html.twig'
));
但是没有用
我知道我可以覆盖整个模板,但我只想为这个表单覆盖它,而不是在我使用这个表单类型的所有地方
有人知道这是否可能吗
感谢我在
/vendor/sonata project/admin bundle/sonata/AdminBundle/Form/Extension/Field/Type/FormTypeFieldExtension.php中找到了大量代码,它实际上设置了一个类型数组,以附加到表单视图,表单视图使用该数组对细枝块渲染进行优先级排序:(第99到105行)
因此,我所要做的就是定义一个名为mycompany\u admin\u content\u galleries\u sonata\u type\u collection\u widget
或mycompany\u admin\u content\u galleries\u slides\u sonata\u type\u collection\u widget的块,它只适用于这个管理表单:)
为了在我的管理类中完成此解决方案,我添加了以下函数:
public function getFormTheme()
{
return array_merge(
parent::getFormTheme(),
array('MyBundle:Gallery:admin.slides.html.twig')
);
}
我创建了MyBundle/Resources/views/Gallery/admin.slides.html.twig
,包含以下内容:
{% use 'SonataAdminBundle:Form:form_admin_fields.html.twig' %} // I think this
line is not really needed as the base admin's form theme uses this file
{% block my_bundle_content_pages_slides_sonata_type_collection_widget %}
// copied and edited the contents of Sonata/DoctrineORMAdminBundle/Resources/views/CRUD/edit_orm_one_to_many.html.twig
{% endblock %}
只需完成回答,您就可以向twig注册模板文件,这样您就不需要将admin类中的术语与“getFormTheme()”合并,请参见:您提到的“定义一个黑色调用…”的地方与在admin.slides.html.twig中创建块的最后一步相同??或者在哪里定义该块?
{% use 'SonataAdminBundle:Form:form_admin_fields.html.twig' %} // I think this
line is not really needed as the base admin's form theme uses this file
{% block my_bundle_content_pages_slides_sonata_type_collection_widget %}
// copied and edited the contents of Sonata/DoctrineORMAdminBundle/Resources/views/CRUD/edit_orm_one_to_many.html.twig
{% endblock %}