我正在将一个TypoScript内容对象与一个fluid模板结合起来。
在页面模板中:
<f:cObject typoscriptObjectPath="lib.myItem" />在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
}
}
}在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>但现在我意识到,因为模板是由renderObj为每个content元素应用的,所以我无法访问fluid的for-each迭代信息。所以,我不能这样做:
<f:for each="{data}" as="item" iteration="itemIterator">
{itemIterator.cycle}
</f:for>为了找出我们在渲染的项目中...因为每个元素都是由renderObj单独呈现的。
如何获取renderObj产品的迭代信息?只有在TS中才有像http://typo3-beispiel.net/index.php?id=9中那样的老而可怕的计数器?
发布于 2016-03-29 22:23:51
你可以制作你自己的IteratorDataProcessor:
<?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;
}
}在Typoscript中,您通过处理器传递数据:
dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
10 {
references.fieldName = image
}
20 = Vendor\MyExt\DataProcessing\IteratorProcessor
}在fluid中,您可以使用例如{iterator.isFirst}访问您在DataProcessor中设置的内容。
发布于 2016-03-30 19:13:22
你应该看看TYPO3内核附带的DatabaseQueryProcessor。
请注意,数据处理只在FLUIDTEMPLATE cObject中工作。
您还可以在文档中找到一个工作示例。
https://stackoverflow.com/questions/36286905
复制相似问题