Search code examples
typo3typoscript

TYPO3 - Typoscript: How to get a field from tt_content as value into lib.contentElement?


In tt_content I added a new field in my sitepackage. Purpose: Add a css-class in the rendered content element. Now I have the problem how to get the value of this field into the typoscript setup.

# Get value for frameAttributes from field tx_dta_site_shadows in tt_content
lib.shadowSettings = COA
lib.shadowSettings {
    10 = TEXT
    10 {
        data = field:tx_dta_site_shadows
    }
}

# Extend frameAttributes typoscript from bk2k/bootstrap-package in sitepackage
lib.contentElement {
    dataProcessing {
        1682424577 {
            data {
                    class < lib.shadowSettings.10.data
                }
            }
        }
    }

The rendered result is:

<div class="field:tx_dta_site_shadows frame frame-default etc...>

But it should be:

<div class="my-shadow-classname-from-tt-content-field frame frame-default etc...>

Can you point me in the right direction?

In use: Typo3 v12.4.16 with bk2k/bootstrap-package


Solution

  • The whole approach looks wrong to me as the field is already retrieved by lib.contentelement which just queries all records of a special colPos (default: 0).

    So you could just use it like this (un-tested):

    lib.contentElement {
        dataProcessing {
            1682424577 {
                data {
                    class = TEXT
                    class.field = tx_dta_site_shadows
                }
            }
        }
        ...
    }
    

    I haven't checked if the data and class keys are correct, the essence is that you have the value already, about the rest you've to check.


    In contrast with your approach you couldn't even reliable assure that the value of lib.shadowSettings belongs to the same record like lib.contentElement and it would need further work to make it reliable (using uid).
    The issue that field:tx_dta_site_shadows is written in the output could be solved with LOAD_REGISTER, but that's superfluous as you would query the same records twice -- yes it's plural because like explained it queries all records with the same colPos.