ProvideStaticVariablesToComponentEvent 

New in version 14.1

The ProvideStaticVariablesToComponentEvent can be used to inject additional static variables into component templates (see Fluid components). As with the ModifyComponentDefinitionEvent ( ModifyComponentDefinitionEvent ), these variables must not have any dependencies on runtime information, as they might be used for static analysis or IDE auto-completion. The RenderComponentEvent ( RenderComponentEvent ) can be used to add variables with runtime dependencies.

Valid use cases for this event might be:

  • providing static design tokens (colors, icons, ...) to all components in a collection
  • generating prefix strings based on the component's name

Example 

EXT:my_extension/Classes/EventListener/ProvideStaticVariablesToComponentListener.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\EventListener;

use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Fluid\Event\ProvideStaticVariablesToComponentEvent;

#[AsEventListener]
final readonly class ProvideStaticVariablesToComponentListener
{
    public function __invoke(ProvideStaticVariablesToComponentEvent $event): void
    {
        // Provide design tokens to all components in a collection
        if ($event->getComponentCollection()->getNamespace() === 'MyVendor\\MyExtension\\Components') {
            $event->setStaticVariables([
                ...$event->getStaticVariables(),
                'designTokens' => [
                    'color1' => '#abcdef',
                    'color2' => '#123456',
                ],
            ]);
        }
    }
}
Copied!

API 

class ProvideStaticVariablesToComponentEvent
Fully qualified name
\TYPO3\CMS\Fluid\Event\ProvideStaticVariablesToComponentEvent

Event to provide additional variables to a Fluid component's template.

These variables should be static and must not have any dependencies on runtime information, such as the request. Think of these variables as something that could be provided as static autocomplete in IDEs: Prefixes based on component name, global design tokens, ...

getComponentCollection ( )
getViewHelperName ( )
Returns
string
getStaticVariables ( )
Returns
array<string,mixed>
setStaticVariables ( array $staticVariables)
param $staticVariables

the staticVariables