如何在TYPO3 Fluid模板中的循环中包装数量检查?

huangapple go评论63阅读模式
英文:

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}&lt;i ; i++)

code below works,

&lt;f:if condition=&quot;{data.order.dinner.0.amount}===1&quot;&gt;
    &lt;f:image src=&quot;{component.componentImages}&quot;&gt;&lt;/f:image&gt;
&lt;/f:if&gt;
&lt;f:if condition=&quot;{data.order.dinner.0.amount}===2&quot;&gt;
    &lt;f:image src=&quot;{component.componentImages}&quot;&gt;&lt;/f:image&gt;
    &lt;f:image src=&quot;{component.componentImages}&quot;&gt;&lt;/f:image&gt;
&lt;/f:if&gt;
&lt;f:if condition=&quot;{data.order.dinner.0.amount}===3&quot;&gt;
    &lt;f:image src=&quot;{component.componentImages}&quot;&gt;&lt;/f:image&gt;
    &lt;f:image src=&quot;{component.componentImages}&quot;&gt;&lt;/f:image&gt;
    &lt;f:image src=&quot;{component.componentImages}&quot;&gt;&lt;/f:image&gt;
&lt;/f:if&gt;

but I would like to optimize the code for the case of any amount, something like

&lt;f:for each=&quot;{data.order.dinner.0.amount}&quot; as=&quot;amount&quot; iteration=&quot;iterator&quot;&gt;
    &lt;f:if condition=&quot;{iterator.index} &lt;= {data.order.dinner.0.amount}&quot;&gt;
          &lt;f:image src=&quot;{component.componentImages}&quot;&gt;&lt;/f:image&gt;
    &lt;/f:if&gt;
&lt;/f:for&gt;

how to will correct first line?
Thanks for any ideas!

答案1

得分: 0

在FLUID中没有明确的计数循环。

但是,如果你知道最大值,你可以使用一个辅助数组:

&lt;f:for each=&quot;{0:1, 1:2, 2:3, 3:4, 4:5, 5:6}&quot; as=&quot;myIndex&quot; iteration=&quot;iterator&quot;&gt;
  &lt;f:if condition=&quot;{myIndex} &lt;= {data.order.dinner.0.amount}&quot;&gt;
    &lt;f:image src=&quot;{component.componentImages}&quot; /&gt;
  &lt;/f:if&gt;
&lt;/f:for&gt;

你还可以使用{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:

&lt;f:for each=&quot;{0:1, 1:2, 2:3, 3:4, 4:5, 5:6}&quot; as=&quot;myIndex&quot; iteration=&quot;iterator&quot;&gt;
  &lt;f:if condition=&quot;{myIndex} &lt;= {data.order.dinner.0.amount}&quot;&gt;
    &lt;f:image src=&quot;{component.componentImages}&quot; /&gt;
  &lt;/f:if&gt;
&lt;/f:for&gt;

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

huangapple
  • 本文由 发表于 2023年3月15日 18:30:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/75743465.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定