Skip to content

Instantly share code, notes, and snippets.

@biesior
Last active May 15, 2017 08:38
Show Gist options
  • Save biesior/0d6b26671015d50f417c to your computer and use it in GitHub Desktop.
Save biesior/0d6b26671015d50f417c to your computer and use it in GitHub Desktop.
TYPO3 Custom condition to check if beLayout selected for page or its parent(s) matches required value
<?php
/**
* Condition to check if beLayout selected for page or its parent(s) matches required value
*
* @param int $layout UID of layout to check
*
* @return bool True if first `found be_layout` OR `backend_layout_next_level` matches the param
*/
function user_beLayout($layout) {
if (TYPO3_MODE != 'FE') return false;
// If layout is set but doesn't match > return false
if ($GLOBALS["TSFE"]->page["backend_layout"] > 0)
return $GLOBALS["TSFE"]->page["backend_layout"] == $layout;
// Otherwise search in rootline for first set `Next level layout` and check if it matches param
foreach ($GLOBALS["TSFE"]->rootLine as $page)
if ($page["backend_layout_next_level"] > 0)
return ($page["backend_layout_next_level"] == $layout);
return false;
}
/**
* TypoScript usage: (according to https://docs.typo3.org/typo3cms/TyposcriptReference/Conditions/Reference/Index.html#condition-userfunc)
*
* [userFunc = user_beLayout(2)]
* // some typoscript
* [end]
*
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment