循环时TYPO3 FLUID分组和限制元素

时间:2016-01-19 09:09:16

标签: typo3 fluid

我试图制作FLuID循环,这将显示4张图片的块。我想实现这样的目标:

  <div class="carousel-inner">
    <div class="item active">
      <div data-target="#carousel" data-slide-to="0" class="thumb"><img src="http://image1.jpg"></div>
      <div data-target="#carousel" data-slide-to="1" class="thumb"><img src="http://image2.jpg"></div>
      <div data-target="#carousel" data-slide-to="2" class="thumb"><img src="http://image3.jpg"></div>
      <div data-target="#carousel" data-slide-to="3" class="thumb"><img src="http://image4.jpg"></div>
    </div>
    <div class="item">
      <div data-target="#carousel" data-slide-to="4" class="thumb"><img src="http://image5.jpg"></div>
      <div data-target="#carousel" data-slide-to="5" class="thumb"><img src="http://image6.jpg"></div>
      <div data-target="#carousel" data-slide-to="6" class="thumb"><img src="http://image7.jpg"></div>
      <div data-target="#carousel" data-slide-to="7" class="thumb"><img src="http://image8.jpg"></div>
    </div>
  </div>

问题是我是FLUID的新手,并且不知道如何只用4个元素进行循环。我的FLUID循环看起来像这样:

    <div class="carousel-inner">                            
        <f:for each="{paginatedAssets}" as="mediaAsset" iteration="iterator">
            <f:if condition="{iterator.index} = 4">
            <div class="item{f:if(condition: '{iterator.index} == 0', then: ' active')}">
                <div data-target="#carousel" data-slide-to="{iterator.index}" class="thumb">
                    <f:render partial="MediaAsset/Detail" section="Detail" arguments="{alt:mediaAsset.alternative,title:mediaAsset.title,mediaAsset:mediaAsset,width:settings.album.thumb.width,height:settings.album.thumb.height,resizeMode:settings.album.thumb.resizeMode}" />
                </div>
            </div>
            </f:if>
        </f:for>
    </div>              

但它显示的是这样的:

    <div class="carousel-inner">
        <div class="item active">
            <div data-target="#carousel" data-slide-to="0" class="thumb">
                <img title="Photo 1" alt="Photo 1" src="fileadmin/_processed_/csm_P1320323_f0d26808a1.jpg" width="800" height="600" />
            </div>
        </div>
        <div class="item">
            <div data-target="#carousel" data-slide-to="1" class="thumb">
                <img title="Photo 2" alt="Photo 2" src="fileadmin/_processed_/csm_P1320326_d00a6dfa33.jpg" width="800" height="600" />
            </div>
        </div>
        ...
        <div class="item">
            <div data-target="#carousel" data-slide-to="n" class="thumb">
                <img title="Photo n" alt="Photo n" src="fileadmin/_processed_/csm_P1234567_f001234567.jpg" width="800" height="600" />
            </div>
        </div>
    </div>

因此每个循环只显示一个(而不是4个)图像。有什么建议?

我将不胜感激任何帮助。

1 个答案:

答案 0 :(得分:2)

您可以使用迭代器的isFirstisLastcycle属性来实现此目的:

<f:for each="{paginatedAssets}" as="mediaAsset" iteration="iterator">
    <f:if condition="{iterator.isFirst}">
        <div class="item active">
    </f:if>
        <div data-target="#carousel" data-slide-to="{iterator.index}" class="thumb">
            <f:render partial ... />
        </div>
    <f:if condition="{iterator.cycle} % 4">
        <f:else>
            </div>
            <div class="item">
        </f:else>
    </f:if>
    <f:if condition="{iterator.isLast}">
        </div>
    </f:if>
</f:for>