Search code examples
typo3typoscriptfluidtypo3-7.6.xtx-mask

How to pass a value from a fluid page template into a ext:mask content element template?


In TYPO3 7 LTS with ext:mask, I would like to pass a value from my page template into the FLUIDTEMPLATE that is rendered via the mask extension.

An example for what I'm trying to achieve:

The content element has content that describes a car: A Volvo, 4WD...

In the page template, I want to display that "car" in different colors. So the page template would be able to command: "get the first car, and show it in green. Then the second car and show it in yellow". (and no, it's got nothing to do with css..)

If this has to be done once onan entire page, I can use

`tt_content.default.mask_car.settings.color = green`

Or (for the record) if the purpose of that variable would be to modify the presentation, I could use:

`tt_content.default.mask_car.settings.file = path/to/Mask/Content/Templates/car_green.html`

But if there are several instances of the same content element on the page, that approach is no good.

How to pass different values into different instances of the same CE on a page?


Solution

  • you could add following TypoScript:

    lib.set_register = LOAD_REGISTER
    lib.set_register.color = TEXT
    lib.set_register.color.current = 1
    
    lib.get_register.color = TEXT
    lib.get_register.color.data = register:color
    
    lib.mask_car < styles.content.get
    lib.mask_car.select.where = colPos=123
    

    And within your page template you set the color with Fluid

    <f:cObject typoscriptObjectPath="lib.set_register.color" data="green"/>
    

    Get your content elements with Fluid

    <f:cObject typoscriptObjectPath="lib.mask_car"/>
    

    And switch the content element's out put within your mask template with Fluid

    <f:if condition="{f:cObject(typoscriptObjectPath: 'lib.get_register.color')} == 'green'">
        <f:then>
            green
        </f:then>
        <f:else>
            not green
        </f:else>
    </f:if>
    

    I hope this helps you to solve your problem.