2016-03-29 13 views
1

Ich kombiniere ein TypoScript CONTENT Objekt mit einer flüssigen Vorlage.Kombination von TypoScript und Fluid: Iterationen?

In der Seitenvorlage:

<f:cObject typoscriptObjectPath="lib.myItem" /> 

In TS:

lib.myItem = CONTENT 
lib.myItem { 
    table = tt_content 
    select.where = colPos = 0 
    select.languageField = sys_language_uid 
    renderObj = FLUIDTEMPLATE 
    renderObj { 
    file = {$customContentTemplatePath}/Myfile.html 
    layoutRootPath = {$customContentLayoutPath} 
    partialRootPath = {$customContentPartialPath} 
    dataProcessing { 
     10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor 
     10.references.fieldName = image 
    } 
    } 
} 

In MyFile.html:

{namespace v=FluidTYPO3\Vhs\ViewHelpers} 

<div class="small-12 medium-6 large-4 columns"> 
    <f:for each="{files}" as="file"> 
     <v:media.image src="{file}" srcset="1200,900,600" srcsetDefault="600" alt="{file.alternative}" treatIdAsReference="1"/> 
    </f:for> 
    <div class="fp-ql-txt"> 
     {data.header} > 
    </div> 
</div> 

Aber jetzt wurde mir klar, dass, weil die Vorlage durch die angelegte renderObj Für jedes Inhaltselement habe ich keinen Zugriff auf die Informationen für die Iteration. Also, ich kann das nicht tun:

<f:for each="{data}" as="item" iteration="itemIterator"> 
    {itemIterator.cycle} 
    </f:for> 

, um herauszufinden, in welchem ​​der erbrachten Produkte sind wir ... da jedes Element einzeln durch renderObj gemacht wird.

Wie bekomme ich die Iterationsinformationen über die Produkte von renderObj? Nur in TS mit den alten und furchterregenden Zählern wie in http://typo3-beispiel.net/index.php?id=9?

Antwort

2

Sie könnten Ihre eigene IteratorDataProcessor machen:

<?php 
namespace Vendor\MyExt\DataProcessing; 

use TYPO3\CMS\Core\SingletonInterface; 
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; 
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface; 
use TYPO3\CMS\Frontend\ContentObject\Exception\ContentRenderingException; 

/** 
* This data processor will keep track of how often he was called and whether it is an 
* even or odd number. 
*/ 
class IteratorProcessor implements DataProcessorInterface, SingletonInterface 
{ 
    /** 
    * @var int 
    */ 
    protected $count = 0; 

    /** 
    * Process data for multiple CEs and keep track of index 
    * 
    * @param ContentObjectRenderer $cObj The content object renderer, which contains data of the content element 
    * @param array $contentObjectConfiguration The configuration of Content Object 
    * @param array $processorConfiguration The configuration of this processor 
    * @param array $processedData Key/value store of processed data (e.g. to be passed to a Fluid View) 
    * @return array the processed data as key/value store 
    * @throws ContentRenderingException 
    */ 
    public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData) 
    { 
     $iterator = []; 
     $iterator['index'] = $this->count; 
     $iterator['isFirst'] = $this->count === 0; 
     $this->count++; 
     $iterator['cycle'] = $this->count; 
     $iterator['isEven'] = $this->count % 2 === 0; 
     $iterator['isOdd'] = !$iterator['isEven']; 
     $processedData['iterator'] = $iterator; 
     return $processedData; 
    } 
} 

In Typoscript übergeben Sie Ihre Daten durch diesen Prozessor:

dataProcessing { 
    10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor 
    10 { 
     references.fieldName = image 
    } 
    20 = Vendor\MyExt\DataProcessing\IteratorProcessor 
} 

In Flüssigkeit Sie das Material, das Sie in Ihren Datenprozessor mit beispielsweise eingestellt zugreifen {iterator.isFirst}.

+0

wow, danke ... Ich werde versuchen, dass, wenn ich eine Minute habe – Urs

+0

Ich denke, Sie haben nicht nur das ad hoc geschrieben - haben Sie diesen Anwendungsfall auch? Denken Sie, dass es ein gültiges Szenario ist? – Urs

+0

Natürlich ist es. Ich werde diesen DataProcessor in einem meiner Projekte verwenden. – Daniel