Skip to content

Instantly share code, notes, and snippets.

@peterkraume
Last active June 25, 2025 20:46
Show Gist options
  • Save peterkraume/29531a7cc8ff8eb2526e7750315d6983 to your computer and use it in GitHub Desktop.
Save peterkraume/29531a7cc8ff8eb2526e7750315d6983 to your computer and use it in GitHub Desktop.

Use Site Settings or Site Configuration in Page TS Config in TYPO3 v13

Inspired by a suggestion on StackOverflow I've implemented this solution to make TYPO3 v13 site settings or site configuration available in Page TSConfig.

Update

Turns out, I was just to stupid and made a typo when trying to access the site settings as described in the official documentation.

Long story short: tx_someextension.fe.loginPage = {$foo.bar} works as documented!

Nevertheless, I learned a lot about the AbstractAstBuilder. :)

Usage

tx_someextension.fe.websitetitle := SiteConfig(your-site:websiteTitle)
tx_someextension.fe.loginPage := SiteSettings(your-site:foo.bar)

Values are fetched e.g. from these files:

config/sites/your-site/config.yaml

base: 'https://www.mycoolwebsite.de'
baseVariants:
  ....
  ....
websiteTitle: 'My cool website'

config/sites/your-site/settings.yaml

foo:
  bar: 123
<?php
declare(strict_types=1);
namespace Vendor\MyExtension\EventListener;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Log\LoggerInterface;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Core\TypoScript\AST\Event\EvaluateModifierFunctionEvent;
use TYPO3\CMS\Core\Utility\GeneralUtility;
#[AsEventListener('vendor-myextension/site-settings-for-tsconfig')]
final readonly class SiteSettingsForTsConfig
{
private LoggerInterface $logger;
public function __construct()
{
$this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
}
public function __invoke(EvaluateModifierFunctionEvent $event): void
{
$functionName = $event->getFunctionName();
if ($functionName === 'SiteSettings' || $functionName === 'SiteConfig') {
$functionArgument = $event->getFunctionArgument();
$functionArguments = explode(':', $functionArgument);
if (count($functionArguments) < 2) {
$this->logger->warning(
sprintf(
'Missing arguments for SiteSettingsForTsConfig function "%s". Expected at least "identifier:key", got "%s".',
$functionName,
$functionArgument
),
['functionName' => $functionName, 'argument' => $functionArgument]
);
$event->setValue('');
return;
}
$siteIdentifier = $functionArguments[0];
$key = $functionArguments[1];
try {
$siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
$site = $siteFinder->getSiteByIdentifier($siteIdentifier);
switch ($functionName) {
case 'SiteConfig':
$configuration = $site->getConfiguration();
if (isset($configuration[$key])) {
$event->setValue((string)$configuration[$key]);
} else {
$this->logger->warning(
sprintf('Configuration key "%s" not found for site "%s" in SiteSettingsForTsConfig function "%s".', $key, $siteIdentifier, $functionName),
['siteIdentifier' => $siteIdentifier, 'key' => $key, 'functionName' => $functionName]
);
$event->setValue('');
}
break;
case 'SiteSettings':
$settings = $site->getSettings();
if ($settings->has($key)) {
$event->setValue((string)$settings->get($key));
} else {
$this->logger->warning(
sprintf('Setting key "%s" not found for site "%s" in SiteSettingsForTsConfig function "%s".', $key, $siteIdentifier, $functionName),
['siteIdentifier' => $siteIdentifier, 'key' => $key, 'functionName' => $functionName]
);
$event->setValue('');
}
break;
}
} catch (SiteNotFoundException $e) {
$this->logger->error(
sprintf('Site not found for SiteSettingsForTsConfig function "%s" with identifier "%s": %s', $functionName, $siteIdentifier, $e->getMessage()),
['siteIdentifier' => $siteIdentifier, 'functionName' => $functionName, 'exception' => $e]
);
$event->setValue('');
} catch (ContainerExceptionInterface | NotFoundExceptionInterface $e) {
$this->logger->critical(
sprintf('Dependency injection error in SiteSettingsForTsConfig function "%s": %s', $functionName, $e->getMessage()),
['functionName' => $functionName, 'exception' => $e]
);
$event->setValue('');
} catch (\Throwable $e) {
$this->logger->error(
sprintf('An unexpected error occurred in SiteSettingsForTsConfig function "%s": %s', $functionName, $e->getMessage()),
['functionName' => $functionName, 'exception' => $e]
);
$event->setValue('');
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment