ProvideStaticVariablesToComponentEvent
New in version 14.1
The
Provide can
be used to inject additional static variables into component templates
(see Fluid components).
As with the ModifyComponentDefinitionEvent
(
Modify), these variables
must not have any dependencies on runtime information, as they might be used for
static analysis or IDE auto-completion. The RenderComponentEvent
(
Render) 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
<?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',
],
]);
}
}
}
API
- class ProvideStaticVariablesToComponentEvent
-
- Fully qualified name
-
\TYPO3\
CMS\ Fluid\ Event\ Provide Static Variables To Component Event
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, ...