首页 > 解决方案 > TYPO3 流体 - 退出 for 循环

问题描述

是否有可能以某种方式打破流体中的 for 循环?

<f:for each="{subItem.image}" as="imageItem">
 <f:if condition="{selectedCategory} == {subItem.imagecategory}">
  Do Stuff
  Exit loop
 </f:if>
</f:for>

我需要遍历几张图像,然后在类别匹配时渲染一个,然后退出循环,因为我只想渲染具有匹配类别的第一张图像。

标签: typo3fluid

解决方案


您可以使用流体变量视图助手:

<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>

推荐阅读