Created
February 17, 2012 00:38
-
-
Save mneuhaus/1849225 to your computer and use it in GitHub Desktop.
Backend Layout Condition for TypoScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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] |
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
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: