Search code examples
typo3typoscripttypo3-6.2.x

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


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?


Solution

  • 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