Symfony 4.1 - sonata admin - 覆盖单个显示映射器项目的模板
Symfony 4.1 - sonata admin - overide template for single showmapper item
我正在尝试像这样覆盖显示操作的单个模板:
public function configureShowFields(ShowMapper $showMapper)
{
$showMapper
->add('smsShipments',null, array(
'template' => 'sms_shipment_list.html.twig'
))
}
但我收到这样的警告:
An error occured trying to load the template
"sms_shipment_list.html.twig" for the field "smsShipments", the
default template "@SonataAdmin/CRUD/base_show_field.html.twig" was
used instead.
因此错误如下:
Uncaught PHP Exception Twig_Error_Runtime: "An exception has been
thrown during the rendering of a template ("Warning: nl2br() expects
parameter 1 to be string, object given")." at
C:\xampp_7\htdocs\project_name\vendor\sonata-project\admin-bundle\src\Resources\views\CRUD\base_show_field.html.twig
line 23
这在 Symfony 3.1 中非常有效。
您能否提供替代解决方案来覆盖单个管理员的显示元素或显示操作?
从这个 SonataAdminBundle guide on the official Symfony 4.x documentation 中提取,我发现您需要在 templates/Namespace/sms_shipment_list.html.twig
中使用您的树枝模板。
然后,然后在选项参数中将其引用为@App/Namespace/sms_shipment_list.html.twig
。
像这样,然后:
public function configureShowFields(ShowMapper $showMapper)
{
$showMapper
->add('smsShipments',null, array(
'template' => '@App/Namespace/sms_shipment_list.html.twig'
))
}
我正在尝试像这样覆盖显示操作的单个模板:
public function configureShowFields(ShowMapper $showMapper)
{
$showMapper
->add('smsShipments',null, array(
'template' => 'sms_shipment_list.html.twig'
))
}
但我收到这样的警告:
An error occured trying to load the template "sms_shipment_list.html.twig" for the field "smsShipments", the default template "@SonataAdmin/CRUD/base_show_field.html.twig" was used instead.
因此错误如下:
Uncaught PHP Exception Twig_Error_Runtime: "An exception has been thrown during the rendering of a template ("Warning: nl2br() expects parameter 1 to be string, object given")." at C:\xampp_7\htdocs\project_name\vendor\sonata-project\admin-bundle\src\Resources\views\CRUD\base_show_field.html.twig line 23
这在 Symfony 3.1 中非常有效。 您能否提供替代解决方案来覆盖单个管理员的显示元素或显示操作?
从这个 SonataAdminBundle guide on the official Symfony 4.x documentation 中提取,我发现您需要在 templates/Namespace/sms_shipment_list.html.twig
中使用您的树枝模板。
然后,然后在选项参数中将其引用为@App/Namespace/sms_shipment_list.html.twig
。
像这样,然后:
public function configureShowFields(ShowMapper $showMapper)
{
$showMapper
->add('smsShipments',null, array(
'template' => '@App/Namespace/sms_shipment_list.html.twig'
))
}