With TYPO3 be_layout, how to choose frontend template correctly (performance-wise)?
Asked Answered
E

2

0

In most of my sites, I've been using the following code to decide which template should be applied to the content rendering - based on what the editor has picked in be_layout:

page.10 = TEMPLATE
page.10 {
    stdWrap.if {
       value = 1
       isInList.data = levelfield:-1,backend_layout_next_level,slide
       isInList.override.data = TSFE:page|backend_layout
    }
    template = FILE
    template.file = fileadmin/templates/main/tmpl/main.html
    ...
}
page.20 = TEMPLATE
page.20 {
    stdWrap.if {
       value = 2
       isInList.data = levelfield:-1,backend_layout_next_level,slide
       isInList.override.data = TSFE:page|backend_layout
    }
    template = FILE
    template.file = fileadmin/templates/main/tmpl/special.html
    ...
}

This works perfectly well.

But I had expected that the if condition would make sure that unnecessary page objects are not processed at at all. Until I've been looking into some performance issues via the admin panel: I discovered that both (all) child objects of page. seem to be rendered - even when the if condition doesn't apply.

It looks like it's processed regularly, and then simply not displayed! So the page rendering time explodes when using multiple templates.

enter image description here

Do I interpret this correctly? What is the correct, perf-efficient way to do this? Or is it a bug?

Electrokinetics answered 23/11, 2014 at 13:14 Comment(0)
E
0

The CASE object doesn't "misbehave" like the "if" condition in stdWrap.

Here's the solution that works for me from http://forum.typo3.org/index.php?t=tree&th=207295&goto=723619&#msg_723619: apply the CASE one level upwards:

page.10 = CASE
page.10 {
    key.data = levelfield:-1,backend_layout_next_level,slide
    key.override.field = backend_layout
    default = TEMPLATE
    default {
        template = FILE
        template.file = fileadmin/templates/main/tmpl/main.html
        marks {     
                LANG < temp.language
                BASEURL < temp.baseurl
                # ... more marks
        }
    }
    # If BE Layout 1 (Standard page) - corresponds to be_layout uid
    # could be omitted, only for beauty
    1 < .default
    # If BE Layout 2 (Landingpage) - corresponds to be_layout uid
    2 < .default
    2 {
        template.file = fileadmin/templates/main/tmpl/main.html
        marks {
                MAINCONTENT < temp.teaser
                CONTENT_NAV >
                CONTENT_NAV =
        }
    }
}

Of course, this could/should also be used with a fluid template

From a site that uses 4 different be_layouts, here are the rendering times - before and after the introduction of the CASE:

enter image description here

Electrokinetics answered 26/11, 2014 at 10:25 Comment(1)
PS I use nc_staticfilecache anyway, but still, this makes a huge difference editors and feusersElectrokinetics
I
1

You can use a CASE object because the file property is stdWrap enabled:

page = PAGE
page {
    typeNum = 0
    bodyTag = <body>

    10 = FLUIDTEMPLATE
    10 {
        [... skipping some stuff...]
        file.stdWrap.cObject = CASE
        file.stdWrap.cObject {
            key.data = levelfield:-1, backend_layout_next_level, slide
            key.override.field = backend_layout

            default = TEXT
            default.value = fileadmin/Templates/layoutA.html

            2 = TEXT
            2.value = fileadmin/Templates/layoutB.html

        }
    }
}
Inhibit answered 25/11, 2014 at 18:20 Comment(0)
E
0

The CASE object doesn't "misbehave" like the "if" condition in stdWrap.

Here's the solution that works for me from http://forum.typo3.org/index.php?t=tree&th=207295&goto=723619&#msg_723619: apply the CASE one level upwards:

page.10 = CASE
page.10 {
    key.data = levelfield:-1,backend_layout_next_level,slide
    key.override.field = backend_layout
    default = TEMPLATE
    default {
        template = FILE
        template.file = fileadmin/templates/main/tmpl/main.html
        marks {     
                LANG < temp.language
                BASEURL < temp.baseurl
                # ... more marks
        }
    }
    # If BE Layout 1 (Standard page) - corresponds to be_layout uid
    # could be omitted, only for beauty
    1 < .default
    # If BE Layout 2 (Landingpage) - corresponds to be_layout uid
    2 < .default
    2 {
        template.file = fileadmin/templates/main/tmpl/main.html
        marks {
                MAINCONTENT < temp.teaser
                CONTENT_NAV >
                CONTENT_NAV =
        }
    }
}

Of course, this could/should also be used with a fluid template

From a site that uses 4 different be_layouts, here are the rendering times - before and after the introduction of the CASE:

enter image description here

Electrokinetics answered 26/11, 2014 at 10:25 Comment(1)
PS I use nc_staticfilecache anyway, but still, this makes a huge difference editors and feusersElectrokinetics

© 2022 - 2024 — McMap. All rights reserved.