Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

Half of the list should be displayed under one <ul> tag and the other half under another <ul> tag.

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.

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>
like image 893
dora Avatar asked Nov 30 '25 23:11

dora


1 Answers

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:

It is a bit extended version of f:for. Here you can check the iteration property. When you use the iteration.index it is the current index of elements. However an elementLimit you have to set.

It is several properties for 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>
like image 94
András Ottó Avatar answered Dec 02 '25 13:12

András Ottó



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!