Search code examples
typo3masktyposcriptfluidtypo3-10.x

Counter for mask elements in a TYPO3 column


In a TYPO3 mask element, I need to know the position of the item in the current column. Like any iterator you would use in a template, but on the level of the column.

I know that with the syntax {cObject}.renderObj.{maskElement}.settings.xyz I can pass in values into the mask element's fluid template. But apparently, TypoScript that goes to settings is not rendered, is that correct?

I tried this:

pageteasers < styles.content.get
pageteasers.select.where = colPos=2
pageteasers {
    renderObj.mask_teaser.settings {
        set_number = LOAD_REGISTER
        set_number {
            counter2.cObject = TEXT
            counter2.cObject.data = register:counter2
            counter2.cObject.wrap = |+1
            counter2.prioriCalc = intval
        }
        get_number = TEXT
        get_number = register:counter2
    }
}

Or simpler

pageteasers < styles.content.get
pageteasers.select.where = colPos=2
pageteasers {
    renderObj.mask_teaser.settings {
        elementId = {cObj:parentRecordNumber}
    }
}

This will output the string {cObj:parentRecordNumber}.

My questions are:

  • Is there another "road" into the mask element from TS than settings where maybe the objects are rendered?
  • How do I number the elements in my column anyway...?

Solution

  • You should go for variables instead of settings, since those are rendered as cObjects and therefor offer you the fully blown stdWrap tool box.

    https://docs.typo3.org/m/typo3/reference-typoscript/master/en-us/ContentObjects/Fluidtemplate/Index.html#variables

    pageteasers < styles.content.get
    pageteasers.select.where = colPos=2
    pageteasers {
        renderObj.mask_teaser {
            variables {
                // count up elements
                // https://stackoverflow.com/questions/67844215/counter-for-mask-elements-in-a-typo3-column // <- Self-reference!
                elementCounter = TEXT
                elementCounter.value = {cObj:parentRecordNumber}
                elementCounter.insertData = 1
            }
        }
    }