Es gibt Code, der in Entwicklungs- und Stagingumgebungen nicht ausgeführt werden sollte, wie z.B. das Webanalyse-Script. Vielleicht will man aber auch bestimmte Features nicht in der Produktion haben. Das unten stehende Snippet bietet diese Möglichkeiten.
<?php /* Snippet "identify_current_domain" * * Returns 1 if the current domain equals a defined domain.tld ("production-domain.tld"). * 0 if not. * * Purpose: Use markup, snippets etc. only in production (eg. Google Analytics), or only in dev environment. * * Properties: * identifydomain = Required, domain to identify. * * Usage: * [[identify_current_domain? &identifydomain=`production-domain.tld`]] * * Using an Output Modifier: * [[identify_current_domain:isequalto=`1`:then=`return my stuff`? &identifydomain=`production-domain.tld`]] * * Using an Output Modifier for Chunks os Snippets (improved performance): * [[[[identify_current_domain:isequalto=`1`:then=`$mychunk`? &identifydomain=`production-domain.tld`]]]] * * You may want to set &identifydomain in a context setting like [[++production_http_host]], at least if you you use this snippet multiple times. * * Works with one subdomain. * */ $output = '0'; // get domain to identify $proddom = $modx->getOption('identifydomain', $scriptProperties, 0); // get the current domain $url = $modx->context->getOption('site_url', null, 'default'); $parsedUrl = parse_url($url); $host = explode('.', $parsedUrl['host']); $hostitems = count($host); // check if the URI contains only one subdomain, otherwise exit if ($hostitems > '3') { return; } // check if current domain meets domain to identify if ($hostitems = '2') { $domain = "$host[0].$host[1]"; if ($domain === $proddom) { $output = "1"; } } if ($hostitems = '3') { $domain = "$host[0].$host[1].$host[2]"; if ($domain === $proddom) { $output = "1"; } } return $output;