.. include:: ../Includes.txt .. _data-processor-guide: =============== Data Processors =============== You can process the data of any content element before it is assigned to the fluid template with the help of :ref:`DataProcessors `. They can help you to reduce overusage of ViewHelpers. In general fluid templates shouldn't include too much logic. For example imagine you have some kind of product content element with these fields: * title (:ref:`String `) * price (:ref:`Float `) Element key: `product`. You probably also would want to show the price with vat added. Now what if you only want to enter the net amount? You probably would either do some mathematical operations in fluid directly or create a ViewHelper for that. But there is a better way by using a data processor: :: `. The `VatProcessor` implements the `DataProcessorInterface` which forces us to implement the `process` method. There are some parameters we can work with: :php:`$cObj` The ContentObjectRenderer. You can do any stdWrap operation with it. :php:`$contentObjectConfiguration` Contains the configuration of the current content object. :php:`$processorConfiguration` Here you can define custom options. See TypoScript configuration section. :php:`$processedData` This is the exact data array you would work with in your fluid templates. Now we can manipulate the data in :php:`$processedData` the way we want it. In our case we enhance the array with another entry `priceGross`. For this we use the `price` defined in our content element and the additional parameter `vat` which we will define in the next section. Register DataProcessor ====================== Now we need to register and configure the data processor for our specific content element. For this we need to add a little bit of TypoScript: .. code-block:: typoscript tt_content { mask_product { dataProcessing { 110 = VENDOR\Extension\DataProcessing\VatProcessor 110 { vat = 19 } } } } The key `mask_product` represents the CType of our Mask element. Mask adds this `mask_` prefix automatically to your specified element key. You can pass any additional parameters to the dataProcessor. They will be available in the :php:`$processorConfiguration` array. .. note:: Mask reserves the key 100 for its own `MaskProcessor`. Mask uses it to fill :ref:`Inline ` and :ref:`File ` fields into the data array. Use in fluid template ===================== Finally we can use our processed data in the fluid template `Product.html`: .. code-block:: html Title: {data.tx_mask_title} Price net: {data.tx_mask_price -> f:format.number(decimals: '2')}€ Price gross: {data.priceGross -> f:format.number(decimals: '2')}€ Note that the added entry `priceGross` does not contain the `tx_mask_` prefix. This way you don't have to rely on multiple ViewHelpers and fluid logic. Move the logic away from you view by using DataProcessors. Have a look at the :ref:`official documentation ` for more examples.