Skip to content

Instantly share code, notes, and snippets.

@mneuhaus
Created February 17, 2012 00:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mneuhaus/1849225 to your computer and use it in GitHub Desktop.
Save mneuhaus/1849225 to your computer and use it in GitHub Desktop.
Backend Layout Condition for TypoScript
<?php
function user_beLayout($layout) {
if($GLOBALS["TSFE"]->page["backend_layout"] > 0 && $GLOBALS["TSFE"]->page["backend_layout"] == $layout)
return true;
foreach ($GLOBALS["TSFE"]->rootLine as $page)
if($page["backend_layout_next_level"] > 0 && $page["backend_layout_next_level"] == $layout)
return true;
return false;
}
?>
// set the default maxW for images to 400,
// for example with a narrow content and sidebar
tt_content.image.20.1.maxW = 400
// change the default maxW for a specific backend layout
// without a sidebar and wider main content area
[userFunc = user_beLayout(2)]
tt_content.image.20.1.maxW = 600
[end]
@sterborg
Copy link

I think this fails if you have more than one backend_layout_next_level and the right one not being the last one.
I would suggest a different foreach loop:

foreach ($GLOBALS["TSFE"]->rootLine as $page) {
    if($page["backend_layout_next_level"] > 0) {
        if ($page["backend_layout_next_level"] == $layout) {
            return true;
        } else {
           return false;
        }
    }
}

@jkrzefski
Copy link

This also fails if the page itself does have a backend_layout but it is not the one that was asked for. I recommend this snippet:

function user_beLayout($layout)
{
    if ($GLOBALS["TSFE"]->page["backend_layout"] > 0) {
        if ($GLOBALS["TSFE"]->page["backend_layout"] == $layout) {
            return true;
        }

        return false;
    }

    foreach ($GLOBALS["TSFE"]->rootLine as $page) {
        if ($page["backend_layout_next_level"] > 0) {
            if ($page["backend_layout_next_level"] == $layout) {
                return true;
            }
            else {
                return false;
            }
        }
    }

    return false;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment