TYPO3 10.4.34中Seminars扩展新增字段前端不显示的解决咨询
解决TYPO3 Seminars扩展新增precondition字段前端单视图不显示问题
问题核心
你当前的钩子代码中直接调用$controller->getPrecondition()是错误的——DefaultController本身没有这个方法,需要从控制器关联的Event模型实例中获取字段值;同时模型覆盖的配置语法也存在格式问题,需要修正。
修复步骤
1. 修正钩子类的字段获取逻辑
修改my_seminar/Classes/Hooks/EventSingleView.php代码,从Event模型实例中获取precondition值:
namespace MyVendor\MySeminar\Hooks; use OliverKlee\Seminars\Hooks\Interfaces\SeminarSingleView; use OliverKlee\Seminars\FrontEnd\DefaultController; class EventSingleView implements SeminarSingleView { public function modifySingleView(DefaultController $controller): void { // 获取当前事件的模型实例 $event = $controller->getEvent(); // 调用模型的getter方法获取precondition值 $precondition = $event->getPrecondition(); // 将值传入模板标记 $controller->setMarker('PRECONDITION', $precondition); } }
2. 修正模型覆盖的配置语法
修改my_seminar/ext_localconf.php中的模型覆盖配置,使用正确的关联数组格式:
// 注册Seminars单视图钩子 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['seminars'][\OliverKlee\Seminars\Hooks\Interfaces\SeminarSingleView::class][] = \MyVendor\MySeminar\Hooks\EventSingleView::class; // 正确覆盖Event模型 $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\OliverKlee\Seminars\Model\Event::class] = [ 'className' => \MyVendor\MySeminar\Domain\Model\Event::class ];
3. 在模板中添加标记
在你使用的Seminars单视图模板(如默认模板typo3conf/ext/seminars/Resources/Private/Templates/FrontEnd/Event/Single.html或自定义模板)中,添加###PRECONDITION###标记,示例:
<div class="seminar-details"> <!-- 其他现有内容 --> <div class="precondition"> <strong>前置条件:</strong> ###PRECONDITION### </div> </div>
4. 清除TYPO3缓存
在TYPO3后端依次执行:
- 清除配置缓存
- 清除类缓存
- 清除页面缓存
确保新的模型类和钩子逻辑被TYPO3正确加载。
内容的提问来源于stack exchange,提问作者Ralf
相关产品推荐
相关产品推荐

