Reputation: 29
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
Upvotes: 0
Views: 739
Reputation: 8604
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.
Upvotes: 0
Reputation: 2684
Shouldn't it be:
lib.layout = CASE
lib.layout {
Additionally you should replace ifEmpty with override and do it the other way around, since TSref says: If the content is empty (trimmed) at this point, the content is loaded with "ifEmpty". Zeros are treated as empty values!
lib.layout {
key.data = levelfield:-2,backend_layout_next_level,slide
key.override.field = backend_layout
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
}
Setting it explicitely to "None" has a value other than zero, so this should be working.
Upvotes: 1