简体   繁体   English

TYPO3,DCE扩展和流体:如何重置f:cycle循环?

[英]TYPO3, DCE extension & Fluid: How to reset an f:cycle loop?

Setup 设定

I am using DCE to create a slider / gallery module, where f:cycle loops trough 20 items. 我正在使用DCE创建一个滑块/图库模块,其中f:cycle循环通过20个项目。 Each item renders an image in a different size. 每个项目都会以不同的尺寸渲染图像。 After 20, the count should start over again at 1. Using VHS I'm also cutting blocks of 5 images, per slide panel. 20之后,计数应重新从1开始。使用VHS ,每个滑动面板还剪切了5张图像的块。

I tried to solve the problem by using f:cycle in following code: 我试图通过在以下代码中使用f:cycle解决问题:

<f:cycle values="{0: '1', 1: '2', 2: '3', 3: '4', 4: '5', 5: '6', 6: '7', 7: '8', 8: '9', 9: '10', 10: '11', 11: '12', 12: '13', 13: '14', 14: '15', 15: '16', 16: '17', 17: '18', 18: '19', 19: '20'}" as="i">

Problem 问题

My problem starts when I have a gallery with less then 20 items, and create a second DCE instance on the same page. 当我拥有一个少于20个项目的图库并在同一页面上创建第二个DCE实例时,我的问题就开始了。 Instead of f:cycle starting fresh, like everything else in the template. 像模板中的所有其他内容一样,不是从f:cycle开始。 It continues the cycle where another instance left off. 它继续另一个实例停止的周期。

For example: 例如:

DCE 1 has 10 items, the second DCE starts counting at 11, instead of 1. DCE 1有10个项目,第二个DCE从11开始计数,而不是1。

Because images are being cropped in different sizes, this completely breaks the layout. 由于图像的裁剪尺寸不同,因此完全破坏了布局。 What could I possibly do to reset f:cycle to make it start at 1, or is there a better way to cycle trough 20 items and start over? 我应该怎么做才能重置f:cycle以使其从1开始,或者有更好的方法来循环槽20个项目并重新开始?

Code

Here is a stripped down version of my code, I'm open for suggestions to improving. 这是我的代码的精简版,我欢迎提出改进建议。 Using either fluid or VHS is fine. 使用流体或VHS都可以。

{namespace dce=ArminVieweg\Dce\ViewHelpers}
{namespace v=FluidTYPO3\Vhs\ViewHelpers}
<f:layout name="None" />

<f:section name="main">

    <f:for each="{field.item -> v:iterator.chunk(count: 5)}" as="col" iteration="row">

        <div class="grid-container{row.cycle}">
            <f:for each="{col}" as="item" iteration="count">

                <f:cycle values="{0: '1', 1: '2', 2: '3', 3: '4', 4: '5', 5: '6', 6: '7', 7: '8', 8: '9', 9: '10', 10: '11', 11: '12', 12: '13', 13: '14', 14: '15', 15: '16', 16: '17', 17: '18', 18: '19', 19: '20'}" as="i">
                    <div class="col{count.cycle}">

                        <f:if condition="{i} == 1">
                            ...
                        </f:if>
                        <f:if condition="{i} == 2">
                            ...
                        </f:if>
                        <f:if condition="{i} == 3">
                            ...
                        </f:if>
                        <f:comment>Etcetera.</f:comment>

                    </div>
                </f:cycle>

            </f:for>
        </div>

    </f:for>

</f:section>    

either you use different cycle variables. 您可以使用不同的循环变量。 maybe this kind will do (I doubt it, the continous counter probably will just be in different named variables): 也许这样会做(我怀疑,连续计数器可能只是在不同的命名变量中):

<f:for each="{col}" as="item" iteration="count">
            <f:cycle values="{0: '1', 1: '2', 2: '3', 3: '4', 4: '5', 5: '6', 6: '7', 7: '8', 8: '9', 9: '10', 10: '11', 11: '12', 12: '13', 13: '14', 14: '15', 15: '16', 16: '17', 17: '18', 18: '19', 19: '20'}" as="i_{count.index}">
                <div class="col{count.cycle}">
                    <f:if condition="{i_{count.index}} == 1">
                        ...
                    </f:if>
                    <f:if condition="{i_{count.index}} == 2">
                        ...
                    </f:if>
                    <f:if condition="{i_{count.index}} == 3">
                        ...
                    </f:if>
                    <f:comment>Etcetera.</f:comment>
                </div>
            </f:cycle>
        </f:for>

or you do the calculation (based on your count iterator) by hand (in TYPO3 < 8 you may need a calculation-VH): 或者您手动进行计算(基于您的count迭代器)(在TYPO3 <8中,您可能需要计算-VH):

<f:for each="{col}" as="item" iteration="count">
    <div class="col{count.cycle}">
        <f:alias map="{modCounter:count.index % 20}">
            <f:if condition="{modCounter} == 1">
                  ...
            </f:if>
            <f:if condition="{modCounter} == 2">
                  ...
            </f:if>
            <f:comment>Etcetera.</f:comment>
        </f:alias>
    </div>
</f:for>

a simple calculation VH: 一个简单的计算VH:

lib.calc = TEXT
lib.calc {
    current = 1
    prioriCalc = 1
}

usage: 用法:

<f:alias map="{modCounter:'{f:cObject(typoscriptObjectPath:\'lib.calc\', data:\'{count.index} % 20\')}'}">


<f:alias map="{modCounter:'{count.index} % 20'->f:cObject(typoscriptObjectPath:'lib.calc')}">

Solution

For anyone looking for a solution, I limited each cycle to the unique uid of the element in which the cycle takes place: 对于任何寻求解决方案的人,我将每个循环限制为发生循环的元素的唯一uid:

<f:cycle values="{0: '1', 1: '2', 2: '3', 3: '4'}" as="i_{contentObject.uid}">
    <f:if condition="{i_{contentObject.uid}} == 1_{contentObject.uid}">
        ...
    </f:if>
    <f:if condition="{i_{contentObject.uid}} == 2_{contentObject.uid}">
        ...
    </f:if>
    <f:if condition="{i_{contentObject.uid}} == 3_{contentObject.uid}">
        ...
    </f:if> 
    <f:if condition="{i_{contentObject.uid}} == 4_{contentObject.uid}">
        ...
    </f:if> 
</f:cycle>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM