You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TYPO3 v12 Bootstrap Package SectionMenu 无法渲染新闻章节求助

TYPO3 v12 + Bootstrap Package:新闻详情页MenuSection渲染新闻章节的解决方案

问题背景

在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]

配置说明

  1. 条件触发:通过tx_news_pi1/news参数判断是否处于新闻详情页
  2. 替换数据处理:移除原针对页面的MenuProcessor,改用DatabaseQueryProcessor直接查询新闻记录
  3. 关联章节查询:通过新闻与内容元素的MM关联表tx_news_domain_model_news_ttcontent_mm,筛选出标记为章节(sectionIndex=1)的内容元素
  4. 模板结构兼容:模拟原MenuSection模板期望的menu数组结构,注入新闻标题、UID等字段,确保默认模板无需修改即可正常渲染
  5. 保留原有功能:保留原无障碍跳转处理器和内容元素图片处理逻辑

注意事项

  • 确保新闻记录已正确关联设置了sectionIndex=1的内容元素
  • 修改后需清除TYPO3全缓存(包括页面缓存和配置缓存)
  • 若使用自定义MenuSection模板,需确保模板逻辑适配新的数据结构(核心是menu数组中每个item包含title和content字段)

内容的提问来源于stack exchange,提问作者JIM

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 18:45:14