$modx->setPlaceholders(array(
'subdomain' => $location->get('subdomain'),
'city' => $location->get('name'),
'state' => $location->get('state'),
),'mfm.');[[!toggleSnippet? &subdomain=`[[+mfm.subdomain]]`]]
$subdomain =$scriptProperties['subdomain'];
This is only set when it is a subdomain and not on the main site. If its not a subdomain the mfm.subdomain is not set at all.
$modx->setPlaceholders(array(
'subdomain' => "",
'city' => "",
'state' => "",
),'mfm.');
It only looks like one when you try to display it in MODX, which removes any unset placeholders as the last step before showing a page.Your solution is a correct one, but I think it would be more efficient to use an if statement to find out if it's a subdomain and set the placeholders accordingly just once rather than setting them twice.
What's happening, in case you're curious, is that the MODX parser makes a number of passes through a page. On each pass, it attempts to replace tags. If a placeholder is set, the corresponding placeholder tag is replaced, but if it's not, the tag is not removed because the placeholder might be set later. Unparsed tags are not removed until the very last pass after all possible attempts to resolve them have failed.
Tags are parsed from the inside out, so MODX tries to replace the placeholder tag, before parsing the whole snippet tag, but fails because it's not set, so the tag arrives intact in the $scriptProperties array.
if (strpos($subdomain, '[[') !== false) {
/* It's the placeholder, act accordingly */
}
$modx->log(modX::LOG_LEVEL_ERROR, $msg);
public function my_debug($message, $clear = false) {
/* @var $chunk modChunk */
global $modx;
$chunk = $modx->getObject('modChunk', array('name'=>'Debug'));
if (! $chunk) {
$chunk = $modx->newObject('modChunk', array('name'=>'Debug'));
$chunk->save();
$chunk = $modx->getObject('modChunk', array('name'=>'Debug'));
}
if ($clear) {
$content = '';
} else {
$content = $chunk->getContent();
}
$content .= $message;
$chunk->setContent($content);
$chunk->save();
}
$msg = 'Value of X: ' . $x;
my_debug($x);
$modx->setPlaceholders(array(
'subdomain' => '',
'city' => $location->get('name'),
'state' => $location->get('state'),
),'mfm.');