Search code examples
typo3typoscripttypo3-6.2.x

TYPO3 6.2/TypoScript: add CSS class to figure tag if caption is not empty


I am wrapping my images in figure tags and the respective image captions in figcaption. Now I want to add a class to the figure tag only if the image caption is not empty. Here’s the code I tried:

tt_content.image.20 {
    renderMethod = figure
    rendering {
        figure {
            oneImageStdWrap.dataWrap = <figure> | </figure>
            oneImageStdWrap.dataWrap {
                override = <figure class="caption"> | </figure>
                override {
                    if.isTrue.caption
                }
            }
            caption.wrap = <figcaption> | </figcaption>
            caption.required = 1
        }
    }
}

I tried several other ways to look up the caption which were all unsuccessful.

As it is written above, every figure gets the class “caption” whether there is a caption or not. Using if.isTrue.field = caption for example does not override, thus returns <figure>|</figure> for every image.

Thanks a lot in advance!


Solution

  • Try with if.isTrue.data = register:allImageCaptions to render the captions. Because FAL data might come from many sources, it is put in a register for each image instead of providing the database rows like in previous releases.

    To see all registers, use

    stdWrap.outerWrap.cObject = TEXT
    stdWrap.outerWrap.data = debug:register