我想在“显示”和“编辑”页面上,在相关的表单字段上方显示一个简单的
<img src="{{ picture.url }} alt="{{ picture.title }} />
标记,以便用户可以看到当前照片,并决定是否更改它(当然,前提是正在编辑的Picture不是新建的)。经过数小时的研究,我一直无法弄清楚如何实现。我想我需要覆盖一些模板,但我有点迷失了…… 能有人给我一条提示吗?
这是我的PictureAdmin类的相关部分。
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('category', NULL, ['label' => 'Catégorie'])
->add('title', NULL, ['label' => 'Titre'])
->add('file', 'file', ['required' => false, 'label' => 'Fichier']) // Add picture near this field
->add('creation_date', NULL, ['label' => 'Date d\'ajout'])
->add('visible', NULL, ['required' => false, 'label' => 'Visible'])
->add('position', NULL, ['label' => 'Position']);
}
protected function configureShowFields(ShowMapper $showMapper)
{
$showMapper
->add('id', NULL, ['label' => 'ID'])
->add('category', NULL, ['label' => 'Catégorie'])
->add('title', NULL, ['label' => 'Titre'])
->add('slug', NULL, ['label' => 'Titre (URL)'])
->add('creation_date', NULL, ['label' => 'Date d\'ajout'])
->add('visible', NULL, ['label' => 'Visible'])
->add('position', NULL, ['label' => 'Position']);
// Add picture somewhere
}