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

TYPO3 v13后端多域名场景下获取页面TypoScript的问题

在TYPO3 v13中获取指定页面的TypoScript(非控制器类场景)

方法1:通过BackendConfigurationManager构造传参(推荐后端环境)

TYPO3 v13中BackendConfigurationManager被声明为final,但可通过构造函数直接传入页面ID,替代原属性赋值操作:

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager;

// 实例化时直接传入目标页面ID
$configurationManager = GeneralUtility::makeInstance(BackendConfigurationManager::class, $pageId);
// 获取完整TypoScript配置
$typoScriptSetup = $configurationManager->getTypoScriptSetup();

return $typoScriptSetup;

方法2:通过TypoScriptFactory构建配置(通用前后端环境)

如果你的类可能在前端缓存环境运行(此时全量TypoScript未初始化),可直接通过TypoScriptFactory结合页面根线路生成配置:

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Configuration\TypoScript\TypoScriptFactory;
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Core\Domain\Repository\PageRepository;

// 获取页面根线路
$pageRepository = GeneralUtility::makeInstance(PageRepository::class);
$rootline = $pageRepository->getRootLine($pageId);

// 关联站点信息
$siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
$site = $siteFinder->getSiteByPageId($pageId);
$siteRootPageId = $site->getRootPageId();

// 生成并获取TypoScript配置数组
$typoScriptFactory = GeneralUtility::makeInstance(TypoScriptFactory::class);
$typoScriptSetup = $typoScriptFactory->create($siteRootPageId, $rootline)->getSetupArray();

return $typoScriptSetup;

错误原因说明

你之前使用ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT报错,是因为在前端缓存生效的场景下,系统不会加载全量TypoScript以提升性能,因此该方法仅适用于后端环境或前端非缓存执行阶段。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 00:05:20