AfterRecordIsRenderedEvent
New in version 15.0 Feature: #110815 - PSR-14 event after a record is rendered
The PSR-14 event
\TYPO3\ is
fired by the
CONTENT
and
RECORDS
content objects
after each single record is rendered. A listener reads the HTML with
get and replaces it with
set, for example to wrap the record in markup of its
own. Whatever a listener writes goes into the page as it is, so escape the
parts that come from the record.
This event covers the records that TypoScript renders, for example through
styles.. For the records that Fluid renders, use
ModifyRenderedRecordEvent,
which this event is the counterpart of.
get usually returns a resolved record. Where TYPO3 cannot
resolve the row, it returns a
Raw with the unprocessed row
instead. A custom
select. that leaves out a system
field, such as the language or the workspace field, has that effect.
TYPO3 skips the event entirely for a table without TCA, and for a row whose
type field a custom
select. left out. No record
object can be built in those cases, and the rendered record stays as it is.
Example
The following listener wraps every content element in an element that names its uid, and leaves the records of other tables alone:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\EventListener;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Frontend\ContentObject\Event\AfterRecordIsRenderedEvent;
final readonly class WrapRenderedRecordListener
{
#[AsEventListener('my_extension/wrap-rendered-record')]
public function __invoke(AfterRecordIsRenderedEvent $event): void
{
$record = $event->getRecord();
if ($record->getMainType() !== 'tt_content') {
return;
}
$event->setRenderedRecord(sprintf(
'<div data-uid="%d">%s</div>',
$record->getUid(),
$event->getRenderedRecord(),
));
}
}
API
-
final class
AfterRecordIsRenderedEvent -
- Fully qualified name
-
\TYPO3\CMS\ Frontend\ Content Object\ Event\ After Record Is Rendered Event
Event which is fired after the CONTENT or RECORDS content object has rendered a single record, allowing listeners to modify the rendered content of the record.