Feature: #108726 - Add PSR-14 Events ModifyRenderedContentAreaEvent and ModifyRenderedRecordEvent
See forge#108726
Description
With the
\TYPO3\, developers can
intercept the rendering of content areas in Fluid templates to modify the output.
This depends on content areas being rendered with the new
<f:
ViewHelper in Fluid templates, see
Introduce Fluid f:render.contentArea ViewHelper.
With the
\TYPO3\, developers can
intercept the rendering of individual records in Fluid templates to modify the output.
This depends on records being rendered with the new
<f: or
<f:
ViewHelpers in Fluid templates, see
Introduce Fluid f:render.record ViewHelper.
Note that any alterations will be output as-is and will not be escaped. If you
process insecure content within an event listener, be sure to escape it properly,
e.g. by applying
htmlspecialchars to it.
Example
An example event listener could look like this:
namespace MyVendor\MyExtension\EventListener;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Fluid\Event\ModifyRenderedContentAreaEvent;
use TYPO3\CMS\Fluid\Event\ModifyRenderedRecordEvent;
final class ModifyRenderedContentEventListener
{
#[AsEventListener]
public function modifyContentArea(ModifyRenderedContentAreaEvent $event): void
{
$content = 'before area<hr />'. $event->getRenderedContentArea() . '<hr />after area';
$event->setRenderedContentArea($content);
}
#[AsEventListener]
public function modifyRecord(ModifyRenderedRecordEvent $event): void
{
$content = 'before record<hr />'. $event->getRenderedRecord() . '<hr />after record';
$event->setRenderedRecord($content);
}
}
Impact
The new events can be used by extension authors to enhance the output of content areas and records rendered in themes.