typo3 - TYPO3 流体 - 退出 for 循环
问题描述
是否有可能以某种方式打破流体中的 for 循环?
<f:for each="{subItem.image}" as="imageItem">
<f:if condition="{selectedCategory} == {subItem.imagecategory}">
Do Stuff
Exit loop
</f:if>
</f:for>
我需要遍历几张图像,然后在类别匹配时渲染一个,然后退出循环,因为我只想渲染具有匹配类别的第一张图像。
解决方案
您可以使用流体变量视图助手:
<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>
推荐阅读
- flutter - 如何在 MapBoxMapController 中使用 SymbolOptions 添加标记
- r - 从矩阵计算调整后的 p 值,同时在 R 中保留矩阵维度
- c# - 如何从另一个类调用上下文以用作参数?
- javascript - Array.reduce() 按对象字段分组并将所有其他字段扩展到其相应的分组对象字段
- jasper-reports - 如果数值介于两个数字之间,如何显示消息?
- java - JAXB。如何使用 JAXB 解析 XML 在 POJO 类中填充内部类/列表?
- c++ - 在交叉编译器目录中运行 .build.sh 文件时出错
- swift - 使用 swift 处理通过 cordova 插件中的 FCM APNs 接口收到的消息
- javascript - 如何在 JavaScript 中使用 Google Map 填充输入字段后填充纬度和经度
- python - 如何在csv文件中创建一个循环?