TYPO3: Count up inside Fluid

旧城冷巷雨未停 提交于 2019-12-11 01:48:53

问题


I'm currently trying to build a carousel with bootstrap in the frontend.

Generating the slides works great.

<f:if condition="{gallery.rows}">
    <f:for each="{gallery.rows}" as="row">
        <f:for each="{row.columns}" as="column">
            <f:if condition="{column.media}">
                <div class="item">
                    <f:media
                        file="{column.media}"
                        width="{column.dimensions.width}"
                        height="{column.dimensions.height}"
                        alt="{column.media.alternative}"
                        title="{column.media.title}"
                    />
                    <div class="carouselText">
                        <div class="container">
                            <h1>{column.media.title}</h1>
                            <f:if condition="{column.media.description}">
                            <p>
                                {column.media.description}
                                <f:if condition="{column.media.link}">
                                    <a href="" class="btn btn-xs">read more</a>
                                </f:if>
                            </p>
                            </f:if>
                        </div>
                    </div>
                </div>
            </f:if>
        </f:for>
    </f:for>
</f:if>

Now I need the little dots for the controls.
The problem is, that they need to count up like this:

<li data-target="#carousel" data-slide-to="0"></li>
<li data-target="#carousel" data-slide-to="1"></li>
<li data-target="#carousel" data-slide-to="2"></li>

Using the same f:for loop as I did to generate the slides in combination with the iteration attribute doesn't work because it's nested in row and columns.
Following output with <f:for each="{row.columns}" as="column" iteration='i'>:

<li data-target="#carousel" data-slide-to="0"></li>
<li data-target="#carousel" data-slide-to="1"></li>
<li data-target="#carousel" data-slide-to="0"></li>

Luckily the gallery array also has an integer in which the amount of images is stored {gallery.count.files} = 3.

There must be an easy way to use for-loops or similar to count up with just an integer and not having an array, right?


回答1:


In TYPO3v8 and above:

{f:variable(name: 'count', value: 0)}
<!-- perform iteration to any depth, recursive or reverse or whatever -->
<li data-slide-to="{count}">..</li>
{f:variable(name: 'count', value: '{count + 1}')}

In TYPO3v7 and earlier you will need the VHS library and substitute f:variable for v:variable.set and {count + 1} for {count -> v:math.sum(b: 1)}.



来源:https://stackoverflow.com/questions/44259106/typo3-count-up-inside-fluid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!