Reputation: 875
Is it somehow possible to break out of a for loop in fluid?
<f:for each="{subItem.image}" as="imageItem">
<f:if condition="{selectedCategory} == {subItem.imagecategory}">
Do Stuff
Exit loop
</f:if>
</f:for>
I need to loop trough a couple of images then render one if the category matches and exit the loop after that since I only want to render the first image with the matching category.
Upvotes: 1
Views: 1890
Reputation: 111
Maybe you can use a dataprocessor to give you an array with just the images in the category, and then you can just grab the first image with {imageItem.0}
.
Have a look at TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
.
Upvotes: 0
Reputation: 6164
You can use Fluid variable view helper:
<f:variable name="imageRendered" value="0" />
<f:for each="{subItem.image}" as="imageItem">
<f:if condition="{selectedCategory} == {subItem.imagecategory} && {imageRendered} == 0">
Do Stuff
Exit loop
<f:variable name="imageRendered" value="1" />
</f:if>
</f:for>
Upvotes: 1