Search code examples
typo3typoscripttypo3-6.1.x

TYPO 3 6.1: Change the rendering of a custom content element depending on the backend layout


I try to write a custom content element which should be rendered depending on the backend_layout or the inherited backend_layout of the page the content element is contained in.

My first attempt

I've got theTypoScript snippet in my template:

lib.layout = CASE
lib.layout {
    key.field = backend_layout
    key.ifEmpty.data = levelfield:-1,backend_layout_next_level,slide

    1 = TEXT
    1.value = START-PAGE-LAYOUT

    2 = TEXT
    2.value = SINGLE-COLUMN-PAGE-LAYOUT

    3 = TEXT
    3.value = TWO-COLUMN-PAGE-LAYOUT

    default = TEXT
    default.value = DEFAULT-OUTPUT
}

If I try to render this in my plugin view like this

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

I get

DEFAULT-OUTPUT

I would expect one of the other three as output.

My second attempt

I also tried

plugin.my_contentelement.settings.layout < lib.layout

and then to use the ContentObjectRenderer but got only the default output.

My question

Does anybody has a nice solution for my problem?

PS: I use TYPO3 6.1.5


Solution

  • key.field should work as by default the current data array is populated by the page data. I don't know why it doesn't work in your case so try this code instead:

    lib.layout = CASE
    lib.layout {
      key.data = page:backend_layout
      key.ifEmpty.data = levelfield:-2,backend_layout_next_level,slide
    
      1 = TEXT
      1.value = START-PAGE-LAYOUT
    
      2 = TEXT
      2.value = SINGLE-COLUMN-PAGE-LAYOUT
    
      3 = TEXT
      3.value = TWO-COLUMN-PAGE-LAYOUT
    
      default = TEXT
      default.value = DEFAULT-OUTPUT
    }
    

    For levelfield:-1,backend_layout_next_level,slide to work, you probably need to add backend_layout_next_level (and better also backend_layout) to $TYPO3_CONF_VARS['FE']['addRootLineFields'] in the installation config file.