TYPO3 v12 Bootstrap Package SectionMenu 无法渲染新闻章节求助
问题背景
在Composer管理的TYPO3 v12项目中,使用Bootstrap Package的MenuSection内容元素时,新闻详情页无法渲染当前新闻的章节索引,反而会读取当前页面的标题(页面无标题时显示为空)。原生MenuSection仅支持关联页面的章节内容,完全没有处理新闻记录关联内容的逻辑——其核心配置(vendor/bk2k/bootstrap-package/Configuration/TypoScript/ContentElement/Element/MenuSection.typoscript)依赖page:uid获取页面下的sectionIndex=1内容元素。
解决方法:TypoScript覆盖适配新闻场景
通过条件TypoScript,在新闻详情页替换MenuSection的数据处理逻辑,直接从当前新闻关联的内容元素中提取章节:
[traverse(request.getQueryParams(), 'tx_news_pi1/news') > 0] tt_content.menu_section { dataProcessing { # 移除原页面导向的MenuProcessor 10 > # 直接查询当前新闻记录及关联章节 10 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor 10 { table = tx_news_domain_model_news uidInList.data = GP:tx_news_pi1|news as = menu dataProcessing { # 通过MM表查询新闻关联的sectionIndex=1的内容元素 20 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor 20 { table = tt_content selectFields = tt_content.* join = tx_news_domain_model_news_ttcontent_mm ON tt_content.uid = tx_news_domain_model_news_ttcontent_mm.uid_foreign where = tx_news_domain_model_news_ttcontent_mm.uid_local = ###CURRENT_UID### AND tt_content.sectionIndex = 1 markers { CURRENT_UID.data = GP:tx_news_pi1|news } orderBy = tx_news_domain_model_news_ttcontent_mm.sorting_foreign as = content # 保留原内容元素的图片处理 dataProcessing { 10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor 10 { references.fieldName = image } } } # 模拟原MenuProcessor的item结构,注入新闻标题等字段 40 = TYPO3\CMS\Frontend\DataProcessing\ArrayProcessor 40 { data { title.data = tx_news_domain_model_news.title uid.data = tx_news_domain_model_news.uid } as = item } # 保留新闻媒体文件处理 30 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor 30 { references.fieldName = media } } } # 保留原无障碍跳转处理器 90 < .90 } } [global]
配置说明
- 条件触发:通过
tx_news_pi1/news参数判断是否处于新闻详情页 - 替换数据处理:移除原针对页面的
MenuProcessor,改用DatabaseQueryProcessor直接查询新闻记录 - 关联章节查询:通过新闻与内容元素的MM关联表
tx_news_domain_model_news_ttcontent_mm,筛选出标记为章节(sectionIndex=1)的内容元素 - 模板结构兼容:模拟原
MenuSection模板期望的menu数组结构,注入新闻标题、UID等字段,确保默认模板无需修改即可正常渲染 - 保留原有功能:保留原无障碍跳转处理器和内容元素图片处理逻辑
注意事项
- 确保新闻记录已正确关联设置了
sectionIndex=1的内容元素 - 修改后需清除TYPO3全缓存(包括页面缓存和配置缓存)
- 若使用自定义
MenuSection模板,需确保模板逻辑适配新的数据结构(核心是menu数组中每个item包含title和content字段)
内容的提问来源于stack exchange,提问作者JIM
相关产品推荐
相关产品推荐

