TYPO3技术咨询:复用pageSetup.ts后能否删setup.ts配置及无控制器扩展的Fluid调用
Q2: 无控制器的TYPO3扩展,如何在后端布局的Fluid模板中调用constants.ts里的配置?
Since your extension doesn’t have a controller, you don’t have a plugin context to pull settings from directly. But there are three straightforward ways to make this work:
Method 1: Mirror the setting to a global TypoScript variable
This is the simplest approach. Update your extension’s setup.ts to copy the plugin setting into a global page variable accessible in backend layouts:
# In your extension's setup.ts page.siteClaim = {$plugin.tx_rmbase.settings.siteClaim}
Then access it in your backend layout Fluid template like this:
{TSFE.config.page.siteClaim}
Method 2: Inject the variable directly into your backend layout config
If you define backend layouts via TypoScript, inject the setting as a template variable directly in the layout definition. Add this to your extension’s setup.ts:
page.backend_layouts { # Replace with your backend layout key/name my_custom_layout { title = My Backend Layout config { # Your existing backend layout grid config here backend_layout { colCount = 1 rowCount = 1 rows { 1 { columns { 1 { name = Main Content colPos = 0 } } } } } } # Path to your backend layout Fluid template template = EXT:rmbase/Resources/Private/Layouts/Backend/MyLayout.html # Inject the setting as a template variable variables { siteClaim = {$plugin.tx_rmbase.settings.siteClaim} } } }
Now you can use {siteClaim} directly in your Fluid template—no extra code needed.
Method 3: Build a custom ViewHelper (for flexibility)
If you need to access multiple settings or want a reusable solution, create a simple ViewHelper to fetch TypoScript values:
- Create the ViewHelper class in your extension:
<?php namespace MonTea\Rmbase\ViewHelpers; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Configuration\TypoScript\TypoScriptService; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; class GetTypoScriptSettingViewHelper extends AbstractViewHelper { public function initializeArguments() { $this->registerArgument('path', 'string', 'TypoScript path to the setting (e.g. plugin.tx_rmbase.settings.siteClaim)', true); } public function render() { $typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class); // Get the full TypoScript setup $fullTypoScript = isset($GLOBALS['TSFE']) ? $GLOBALS['TSFE']->tmpl->setup : []; $plainTypoScript = $typoScriptService->convertTypoScriptArrayToPlainArray($fullTypoScript); // Fetch the value using the provided path return \TYPO3\CMS\Core\Utility\ArrayUtility::getValueByPath($plainTypoScript, $this->arguments['path'], '.'); } }
- Use it in your Fluid template:
{namespace rmbase=MonTea\Rmbase\ViewHelpers} <p>{rmbase:getTypoScriptSetting(path: 'plugin.tx_rmbase.settings.siteClaim')}</p>
Note: For backend contexts, you might need to ensure $GLOBALS['TSFE'] is initialized—if you run into issues, you can add code to initialize it manually, but the first two methods are usually easier for backend layouts.
内容的提问来源于stack exchange,提问作者MonTea

