简体   繁体   English

循环阵列时TYPO3 FLUID条件

[英]TYPO3 FLUID conditions while looping array

I have an array which contains a list of names. 我有一个包含名单列表的数组。 In the front end, this has to be listed in a listed way. 在前端,必须以列出的方式列出。 Using the <ul> and <li> tags. 使用<ul> and <li>标签。

Half of the list should be displayed under one <ul> tag and the other half under another <ul> tag. 列表的一半应显示在一个<ul>标记下,另一半显示在另一个<ul>标记下。

like this: 像这样:

<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>

<ul>
<li>Four</li>
<li>Five</li>
<li>Six</li>
</ul>

Now the problem is in FLUID I did not find a way to end the <ul> tags when the array loops half of the elements. 现在问题是在FLUID中,当数组循环一半元素时,我没有找到结束<ul>标记的方法。

I want to do something like this 我想做这样的事情

<f:for each="{my_array}" as="item">
<li>{item}</li>
<!-- if condition where count=(my_array%2) then use </ul><ul>-->
</f:for>

I think you should get the id in PHP for the element in the middle and then you can use a simple if, like this: 我认为您应该在PHP中获取中间元素的id,然后您可以使用简单的if,如下所示:

It is a bit extended version of f:for . 它是f:for一个扩展版本。 Here you can check the iteration property. 在这里,您可以检查iteration属性。 When you use the iteration.index it is the current index of elements. 当您使用iteration.index时,它是元素的当前索引。 However an elementLimit you have to set. 但是你必须设置一个elementLimit。

It is several properties for iteration : isFirst,isLast, isEven, isOdd, total, cycle, index. 它是iteration几个属性:isFirst,isLast,isEven,isOdd,total,cycle,index。

Here is an article about it. 这是一篇关于它的文章。

UPDATED example: 更新的例子:

<f:for each="{my_array}" as="item" iteration="itemIterator">
    <li>{item}</li>
    <f:if condition="{itemIterator.index} = {elementLimit}">
        </ul><ul>
    </f:if>
</f:for>

This should work. 这应该工作。 The only problem is when there is an odd amount of menu entries. 唯一的问题是当有奇数量的菜单条目时。

<f:for each="{my_array}" as="item" iteration="itemIterator">
    <ul>
        <li>{item}</li>
        <f:if condition="{itemIterator.iterator}%({itemIterator.total}/2) == 0">
            </ul><ul>
        </f:if>
    </ul>
</f:for>

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

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