我有一个
BorrowingCrudController
,其中包含预期返回日期字段和最终返回日期字段。
我想要的是创建一个条件来检查
final_return_date
字段的值,然后调用 setTemplatePath
方法,如果 final_return_date
字段为空,则使用自定义模板渲染预期返回日期,如果不为空,则正常渲染它.
这是我的代码:
public function configureFields(string $pageName): iterable
{
yield IntegerField::new('id')->hideOnForm();
yield AssociationField::new('user', 'Utilisateur');
yield AssociationField::new('book', 'Titre du livre');
yield AssociationField::new('book', 'ID du livre')->formatValue(function ($value) {
return $value->getId();
});
yield BooleanField::new('prolongated', 'Prolongé')->renderAsSwitch(false);
yield DateTimeField::new('borrowingDate', 'Date d\'emprunt')
->formatValue(function ($value) {
return $value->format('d-m-Y');
});
yield DateTimeField::new('expectedReturnDate', 'Date de retour prévu')->formatValue(function ($value) {
return $value->format('d-m-Y');
})
->setTemplatePath('admin/field/date_expected_return.html.twig');
yield DateTimeField::new('finalReturnDate', 'Date de retour finale')->formatValue(function ($value) {
if ($value === null) {
return null;
} else {
return $value->format('d-m-Y');
}
});
}
我尝试创建一个bool变量,然后调用
formatValue
方法检索final_return_date字段的值,然后相应地修改bool以显示相应的模板,但它不起作用。
好的,我成功了,方法如下:
我必须覆盖 EasyAdmin Bundle 中的 index.html.twig 模板。 为此,我访问了位于
的index.html.twig文件供应商 asycorp asyadmin-bundle\src\Resources iew