I’ve had a look through the PHx code. The problem as I see it is that PHx doesn’t distinguish between tags with a modifier and tags without modifiers. Ideally PHx should leave tags without a modifier alone and let modx->parseDocumentSource() (or any snippets that use them) handle them. I made some changes to the PHx code that does this for [+placeholder+] style place holders at least. This seems to alleviate pixelschute’s problem.
Source from function ParseValues starting from line 83. Changes are commented.
<?php
if ( preg_match_all('~\[(\+|\*|\()([^:\+\[\]]+)([^\[\]]*?)(\1|\))\]~s',$template, $matches)) {
//$matches[0] // Complete string that's need to be replaced
//$matches[1] // Type
//$matches[2] // The placeholder(s)
//$matches[3] // The modifiers
//$matches[4] // Type (end character)
$count = count($matches[0]);
$var_search = array();
$var_replace = array();
for($i=0; $i<$count; $i++) {
$replace = NULL;
$match = $matches[0][$i];
$type = $matches[1][$i];
$type_end = $matches[4][$i];
$input = $matches[2][$i];
$modifiers = $matches[3][$i];
//MOD by JJC - skip if no modifier
if(empty($modifiers)) continue;
//end MOD
$var_search[] = $match;
//... skipped rest of code
}
?>
Source from function Parse starting from line 51. Again, changes are commented.
<?php
function Parse($template='') {
global $modx;
// If we already reached max passes don't get at it again.
if ($this->curPass == $this->maxPasses) return $template;
// Set template pre-process hash
$st = md5($template);
// Replace non-call characters in the template: [, ]
$template = preg_replace($this->safetags[0],$this->safetags[1],$template);
// To the parse mobile.. let's go! *insert batman tune here*
$template = $this->ParseValues($template);
// clean up unused placeholders that have modifiers attached (MODx can't clean them)
preg_match_all('~\[(\+|\*|\()([^:\+\[\]]+)([^\[\]]*?)(\1|\))\]~s', $template, $matches);
if ($matches[0]) {
//MOD by JJC - skip if no modifier set - leave to document parser to deal with
foreach($matches[3] as $key => $match)
if( substr($match,0,1)!=':' ) unset($matches[0][$key]);
//end MOD
$template = str_replace($matches[0], '', $template);
$this->Log("Cleaning unsolved tags: \n" . implode("\n",$matches[2]) );
}
//... skipped rest of code
}
?>
This may not be the best and most generic solution but at least it avoids all kinds of workarounds without unwanted side effects (I hope anyway).
EDIT: According to BS this hack interferes with the recursive behavior of PHX. Look to the
PHX support thread to see how things are going. I personally don’t use PHX so I’ll leave it to BS to tackle this issue further. I do think it is a "weakness" in PHX that needs addressing at some point.