英文:
how to wrap the quantity check in TYPO3 Fluid templates in a loop?
问题
我需要根据变量“amount”的值显示图像。现在我分别检查它是否等于1、2或3。
如何在TYPO3 Fluid模板中的循环中包装数量检查?
作为类型
<f:for each="{data.order.dinner.0.amount}" as="amount" iteration="iterator">
<f:if condition="{iterator.index} <= {amount}">
<f:image src="{component.componentImages}"></f:image>
</f:if>
</f:for>
如何正确更改第一行?
谢谢任何建议!
英文:
I need to show the image as many times as the amount variable. Now I separately check whether it is equal to 1, or 2, or 3.
How to wrap the quantity check in TYPO3 Fluid templates in a loop?
as a type
for ( i=1; if {amount}<i ; i++)
code below works,
<f:if condition="{data.order.dinner.0.amount}===1">
<f:image src="{component.componentImages}"></f:image>
</f:if>
<f:if condition="{data.order.dinner.0.amount}===2">
<f:image src="{component.componentImages}"></f:image>
<f:image src="{component.componentImages}"></f:image>
</f:if>
<f:if condition="{data.order.dinner.0.amount}===3">
<f:image src="{component.componentImages}"></f:image>
<f:image src="{component.componentImages}"></f:image>
<f:image src="{component.componentImages}"></f:image>
</f:if>
but I would like to optimize the code for the case of any amount, something like
<f:for each="{data.order.dinner.0.amount}" as="amount" iteration="iterator">
<f:if condition="{iterator.index} <= {data.order.dinner.0.amount}">
<f:image src="{component.componentImages}"></f:image>
</f:if>
</f:for>
how to will correct first line?
Thanks for any ideas!
答案1
得分: 0
在FLUID中没有明确的计数循环。
但是,如果你知道最大值,你可以使用一个辅助数组:
<f:for each="{0:1, 1:2, 2:3, 3:4, 4:5, 5:6}" as="myIndex" iteration="iterator">
<f:if condition="{myIndex} <= {data.order.dinner.0.amount}">
<f:image src="{component.componentImages}" />
</f:if>
</f:for>
你还可以使用{iterator.index}
或{iterator.cycle}
处理其他类型的数组。
英文:
There is no explicit counting loop in FLUID.
but you may could use a helper array if you know a maximum value:
<f:for each="{0:1, 1:2, 2:3, 3:4, 4:5, 5:6}" as="myIndex" iteration="iterator">
<f:if condition="{myIndex} <= {data.order.dinner.0.amount}">
<f:image src="{component.componentImages}" />
</f:if>
</f:for>
you also may use {iterator.index}
or {iterator.cycle}
for other kind of arrays.
ADDon:
Another option for showing multiple iteration of an image would be a repeating background image, where the size/width of the container is calculated by the number of repeats.
Often this is done by ratings which may include fractions as result from a average calculation. In this way for example you can show 3.14 stars (from 5 stars).
methods to show ratings
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论