Events¶
New in version 0.7.0: Feature: #10 - Introduce BeforeRenderingEvent and AfterRenderingEvent
There are several events available that allow to influence the rendering. Event listeners must be registered via the service configuration. More information can be found in the official TYPO3 documentation.
BeforeRenderingEvent¶
This event is triggered directly before the compiled template is rendered along with the provided data. This allows the data to be manipulated once again before it is passed to the Renderer.
Example:
# Classes/EventListener/BeforeRenderingListener.php
namespace Vendor\Extension\EventListener;
use Fr\Typo3Handlebars\Event\BeforeRenderingEvent;
class BeforeRenderingListener
{
public function modifyRenderData(BeforeRenderingEvent $event): void
{
$data = $event->getData();
// Do anything...
$event->setData($data);
}
}
AfterRenderingEvent¶
After the Renderer has completely rendered the template using the provided data,
the AfterRenderingEvent
is triggered. This can be used to subsequently
influence the rendering result.
Example:
# Classes/EventListener/AfterRenderingListener.php
namespace Vendor\Extension\EventListener;
use Fr\Typo3Handlebars\Event\AfterRenderingEvent;
class AfterRenderingListener
{
public function modifyRenderedContent(AfterRenderingEvent $event): void
{
$content = $event->getContent();
// Do anything...
$event->setContent($content);
}
}