Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony 如何在SonataAdmin中自定义特定的字段渲染?_Symfony_Sonata Admin - Fatal编程技术网

Symfony 如何在SonataAdmin中自定义特定的字段渲染?

Symfony 如何在SonataAdmin中自定义特定的字段渲染?,symfony,sonata-admin,Symfony,Sonata Admin,在我的Admin类中,在configureFormFields方法中,我有复选框fieldextractImageSide: protected function configureFormFields(FormMapper $formMapper) { $formMapper // ... ->add('excerptImageSide') ; } 现在,在管理创建/编辑页面中,复选框呈现为: 正如你们所看到的,复选框在标签下,但我

在我的
Admin
类中,在
configureFormFields
方法中,我有复选框field
extractImageSide

protected function configureFormFields(FormMapper $formMapper)
{
     $formMapper
      // ...
         ->add('excerptImageSide')
     ;
} 
现在,在管理创建/编辑页面中,复选框呈现为:


正如你们所看到的,复选框在标签下,但我想把它放在一行上。所以我的问题是如何为特定的场渲染应用自定义模板

我知道的最简单的方法是用(…)将字段包装成一个具有类的
->,并制作一些自定义CSS:

管理

 $formMapper
  // ...
     ->with('YourSection', array('class' => 'floating-checkboxes'))
         ->add('excerptImageSide')
     ->end()
 ;
CSS

.floating-checkboxes label{
    float: left;      // Make the label floating
    min-width: 185px; // Keep a correct space between the field and its label
}

要加载自定义样式表或完全覆盖字段模板,请查看。

谢谢您的回复!这确实是一个有效的解决方案。我是否正确理解,为了覆盖表单的原始模板,我需要扩展
SonataAdminBundle:CRUD:base_edit.html.twig
?您应该看看这个问题。但是覆盖一个完整的字段来添加几行html/css对我来说似乎有些过分,这是出于您自己的欣赏:)。