Using the ContentObjectRenderer
In some cases, the presence of the current Content may
be necessary in the Data. For this case a
CPSIT\ interface is
provided, which can be used in combination with the trait
CPSIT\.
Usage
-
Transfer of the
ContentObject Renderer If the rendering process is triggered via TypoScript, the
Datais automatically assigned the current instance of theProcessor Content(via theObject Renderer cproperty). It can then pass this to theObj Data:Provider # Classes/DataProcessing/CustomProcessor.php namespace Vendor\Extension\DataProcessing; use CPSIT\Typo3Handlebars\DataProcessing\AbstractDataProcessor; class CustomProcessor extends AbstractDataProcessor { protected function render(): string { $this->provider->setContentObjectRenderer($this->cObj); // ... } }Copied! -
Assure
Contentis availableObject Renderer In the
Data, the existence of theProvider Contentcan be easily checked if the associated trait is used:Object Renderer # Classes/Data/CustomProvider.php namespace Vendor\Extension\Data; use CPSIT\Typo3Handlebars\ContentObjectRendererAware; use CPSIT\Typo3Handlebars\Data\DataProvider; use CPSIT\Typo3Handlebars\Data\Response\ProviderResponse; use CPSIT\Typo3Handlebars\Traits\ContentObjectRendererAwareTrait; class CustomProvider implements DataProvider, ContentObjectRendererAware { use ContentObjectRendererAwareTrait; public function get(array $data): ProviderResponse { $this->assertContentObjectRendererIsAvailable(); // ... } }Copied! -
Use the
ContentObject Renderer If successful, the
Contentcan then be used, for example, to parse database content generated using RTE:Object Renderer # Classes/Data/CustomProvider.php namespace Vendor\Extension\Data; use CPSIT\Typo3Handlebars\ContentObjectRendererAware; use CPSIT\Typo3Handlebars\Data\DataProvider; use CPSIT\Typo3Handlebars\Data\Response\ProviderResponse; use CPSIT\Typo3Handlebars\Traits\ContentObjectRendererAwareTrait; +use Vendor\Extension\Data\Response\CustomProviderResponse; class CustomProvider implements DataProvider, ContentObjectRendererAware { use ContentObjectRendererAwareTrait; public function get(array $data): ProviderResponse { $this->assertContentObjectRendererIsAvailable(); - // ... + + $text = $this->parseText($data); + + return new CustomProviderResponse($text); } + + private function parseText(string $plaintext): string + { + return $this->contentObjectRenderer->parseFunc($plaintext, [], '< lib.parseFunc_RTE'); + } }Copied!