Search code examples
typo3fluidtypo3-9.x

TYPO3 9 and Flux: Adding an element / section / container multiple times


I'm using TYPO3 9.5.26 and Flux 9.4.2 and I would like to create a calendar-element with exactly five elements/days. Each day needs some input fields. It would look something like this:

Calendar:

  • Day 1: Offer ID, Image
  • Day 2: Offer ID, Image
  • Day 3: ...

Considering DRY, I would like to use some kind of for-loop, but this doesn't work. What I tried:

<f:section name="Configuration">
 ...
    <f:for each="{0:1, 1:2, 2:3, 3:4}" as="foo" key="number">
          <flux:field.multiRelation label="Angebot Tag 1" name="offerDay1" table="tx_data_domain_model_offer">
          </flux:field.multiRelation>
    </f:for>

If I enter five of the multiRelation-fields, it works as expected but as these subelements will get more input fields the code would get bloated.

I also tried using a flux section but it seems like there is no option of limiting the number of elements to exactly five.


Solution

  • Thanks to j4k3's last comment on my question I found out what I was doing wrong: I was trying to apply multiple fields with the same name which isn't allowed. This code using the 'key' works (could also use iteration):

    <f:for each="{0:1, 1:2, 2:3, 3:4}" as="foo" key="number">
              <flux:field.multiRelation label="Angebot Tag {number}" name="offerDay{number}" table="tx_data_domain_model_offer">
              </flux:field.multiRelation>
    </f:for>