* ``` * * or: * * ```html * {content.main -> f:render.contentArea()} * ``` * * or with markup before and after rendered record by using the "recordAs" argument * in combination with the ` ViewHelper `_: * * ```html * * before {record.fullType} * * after {record.fullType} * * ``` * * @see https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-render-contentarea */ final class ContentAreaViewHelper extends AbstractViewHelper { /** * @var bool use content as-is */ protected $escapeOutput = false; public function __construct( private readonly EventDispatcherInterface $eventDispatcher, ) {} public function initializeArguments(): void { parent::initializeArguments(); $this->registerArgument('contentArea', ContentArea::class, 'A content area from the page-content processor'); $this->registerArgument('recordAs', 'string', 'Name of the variable to store the current record in, if you want to use it in the before/after content.'); } public function render(): string { // use argument and fallback to renderChildren for inline records. $contentArea = $this->arguments['contentArea'] ?? $this->renderChildren(); if (!$contentArea instanceof ContentArea) { throw new InvalidArgumentValueException('The "contentArea" argument must be an instance of ' . ContentArea::class, 1770212183); } $result = ''; if ($this->arguments['recordAs'] !== null) { $globalVariableProvider = $this->renderingContext->getVariableProvider(); foreach ($contentArea->getRecords() as $record) { $localVariableProvider = new StandardVariableProvider([$this->arguments['recordAs'] => $record]); $scopedVariableProvider = new ScopedVariableProvider($globalVariableProvider, $localVariableProvider); $this->renderingContext->setVariableProvider($scopedVariableProvider); $result .= $this->renderChildren(); } $this->renderingContext->setVariableProvider($globalVariableProvider); } else { foreach ($contentArea->getRecords() as $record) { $result .= $this->renderingContext->getViewHelperInvoker()->invoke( RecordViewHelper::class, [ 'record' => $record, ], $this->renderingContext, ); } } $event = $this->eventDispatcher->dispatch( new ModifyRenderedContentAreaEvent( renderedContentArea: $result, contentArea: $contentArea, request: $this->getRequest(), ), ); return $event->getRenderedContentArea(); } private function getRequest(): ServerRequestInterface { if (!$this->renderingContext->hasAttribute(ServerRequestInterface::class)) { throw new \RuntimeException('Required request not found in RenderingContext', 1769183896); } return $this->renderingContext->getAttribute(ServerRequestInterface::class); } }