ModifyRenderedRecordEvent
New in version 14.2 Feature: #108726 - Introduce Fluid f:render.record ViewHelper
The
Modify is fired
after the
f:render.record ViewHelper
rendered one record, and before the result reaches the template. A listener
reads the HTML with
get and replaces it with
set, for example to wrap a content element in markup of
its own.
Without the argument record, the
f:render.contentArea ViewHelper
renders each record of the area with f:, so the event is fired
for these records as well. With record, the event is only fired if the
content of the tag renders the record with f:.
The event also carries the record and the request. Whatever a listener writes goes into the page as it is, so escape the parts that come from the record.
To change a whole column of the backend layout instead of a single record, use ModifyRenderedContentAreaEvent.
Example
The following listener wraps every record in an element that names its type and uid:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\EventListener;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Fluid\Event\ModifyRenderedRecordEvent;
final readonly class WrapRenderedRecordListener
{
#[AsEventListener('my_extension/wrap-rendered-record')]
public function __invoke(ModifyRenderedRecordEvent $event): void
{
$record = $event->getRecord();
$event->setRenderedRecord(sprintf(
'<div data-record="%s" data-uid="%d">%s</div>',
htmlspecialchars($record->getFullType()),
$record->getUid(),
$event->getRenderedRecord(),
));
}
}
API
-
final class
ModifyRenderedRecordEvent -
- Fully qualified name
-
\TYPO3\CMS\ Fluid\ Event\ Modify Rendered Record Event
Event to modify the rendered record output.
This can be used to alter the final HTML of a record (eg. content element), for example to render a debug wrapper around it.