ModifyRenderedContentAreaEvent
New in version 14.2 Feature: #108726 - Add PSR-14 events ModifyRenderedContentAreaEvent and ModifyRenderedRecordEvent
The
Modify is
fired after the
f:render.contentArea ViewHelper
rendered a content area, which is the HTML of every record in one column of
the backend layout. A listener reads the HTML with
get and replaces it with
set.
get returns the
Content, which answers the name and the
identifier of the area, its col, its slide mode, and the records it
collected. Whatever a listener writes goes into the page as it is, so escape
the parts that come from a record.
To change a single record instead of a whole area, use ModifyRenderedRecordEvent.
Example
The following listener marks an area that rendered no record, which makes a gap in a layout visible during development:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\EventListener;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Fluid\Event\ModifyRenderedContentAreaEvent;
final readonly class WrapRenderedContentAreaListener
{
#[AsEventListener('my_extension/wrap-rendered-content-area')]
public function __invoke(ModifyRenderedContentAreaEvent $event): void
{
$contentArea = $event->getContentArea();
if ($contentArea->getRecords() !== []) {
return;
}
// Mark an area that rendered nothing, to find gaps in a layout
$event->setRenderedContentArea(sprintf(
'<div class="my-empty-area">%s is empty</div>',
htmlspecialchars($contentArea->getName()),
));
}
}
API
-
final class
ModifyRenderedContentAreaEvent -
- Fully qualified name
-
\TYPO3\CMS\ Fluid\ Event\ Modify Rendered Content Area Event
Event to modify the rendered content area output.
This can be used to alter the final HTML of a content area, for example to render a debug wrapper around it.