Typo3 and conditional TypoScript includes

Since a long time it’s possible to split your TypoScripts into external files and include them from your template via
<INCLUDE_TYPOSCRIPT: source="FILE: fileadmin/fileToInclude.ts">
So it’s very easy to use your favorite editor and, more important, organize the TypoScript-Files into smaller, reusable chunks.

My common setup is something like that:
Template-Code:
<INCLUDE_TYPOSCRIPT: source="FILE: fileadmin/tpl/include.ts">

fileadmin/tpl/include.ts:
<INCLUDE_TYPOSCRIPT: source="FILE:fileadmin/tpl/ts/site.ts">
<INCLUDE_TYPOSCRIPT: source="FILE:fileadmin/tpl/ts/defaults.ts">
<INCLUDE_TYPOSCRIPT: source="FILE:fileadmin/tpl/ts/header.ts">
<INCLUDE_TYPOSCRIPT: source="FILE:fileadmin/tpl/ts/menu.ts">
<INCLUDE_TYPOSCRIPT: source="FILE:fileadmin/tpl/ts/plugin_news.ts">
<INCLUDE_TYPOSCRIPT: source="FILE:fileadmin/tpl/ts/plugin_facebook.ts">

But there is one large downside. Every include adds an [GLOBAL] at the end of file. So it’s not possible to include files based on a multi level condition. For example if you like to develop a new design and want to test it on a test domain. For more information see https://forge.typo3.org/issues/16525

But since Typo3 7.6 there is something which can help.
They’ve added an extra parameter to the include statement: condition. So you can include the statements based on a condition and there is no need to have the condition inside the TS. So it’s very easy to switch between two TS-Sets bases on a domain.

Just use this in your template:
<INCLUDE_TYPOSCRIPT: source="FILE: fileadmin/tpl/ts/includes.ts" condition="userFunc = userIsNotDomain('new.example.com')" >
<INCLUDE_TYPOSCRIPT: source="FILE: fileadmin/tpl2016/ts/includes.ts" condition="userFunc = userIsDomain('new.example.com')" >

And add this to your AdditionalConfiguration.php:

function userIsDomain( $domain ) {
if ( strcmp( $_SERVER['HTTP_HOST'], $domain) == 0 ) return true;
return false;
}
function userIsNotDomain( $domain ) { return !userIsDomain( $domain ); }