fluidtypo3-7.6.xview-helpers

Typo3 Fluid - Add Counter in dynamic Form


simply i just want to have a counter that starts at 0 and gets incremented everytime the if-condition inside my for each is true. I know how to achieve this in javascript .. The countervar should stay in front of Entry inside the Label.

<f:for each="{house.offers}" as="offer" key="index">
            <f:if condition="{offer.offerCategory} == {category}">
                <f:then>
                    <div class="form-element-wrap removable">
                        <label class="label" for="{index}"> **Entry** for {category.title}</label>
                        <f:form.hidden name="house[offers][{index}][__identity]" value="{offer.uid}" />
                        <f:form.textfield name="house[offers][{index}][title]" id="{index}" class="text form-element" value="{offer.title}" />
                        <button class="remove-button" role="button" aria-label="delete-button"></button>
                    </div>
                </f:then>
                <f:else>
                    <f:form.hidden name="house[offers][{index}][__identity]" value="{offer.uid}" />
                </f:else>
            </f:if>
        </f:for>

Solution

  • Prior to TYPO3v8 you could use EXT:vhs which gives you a viewhelper to set Fluid variables.

    The calculation could be done via TypoScript then:

    <v:variable.set name="counter"><f:cObject typoscriptObjectPath="lib.calc" data="{counter} + 1" /></v:variable.set>
    
    lib.calc = TEXT
    lib.calc.current = 1
    lib.calc.prioriCalc = 1