$tpl = isset($tpl) ? $modx->getChunk($tpl):' <div class="summaryPost"> <h3>[+title+]</h3> <div>[*picture*]</div> <div>[+summary+]</div> <div>[*location*] - [*price*]</div> <p> [+link+]</p> <div style="text-align:right;">by <strong>[+author+]</strong> on [+date+]</div> </div>
$fields = array('[+title+]','[+summary+]','[+link+]','[+author+]','[+date+]','[+id+]'); $values = array($resource[$x]['pagetitle'],$summary,$link,$username,strftime($date, $resource[$x][$datetype]),$resource[$x]['id']);
$output .= str_replace($fields,$values,$tpl);
David,
The [+tags+] are parsed manually and not automatically. Each additional variable to be parsed must be added in these lines:
$fields = array('[+title+]','[+summary+]','[+link+]','[+author+]','[+date+]','[+id+]'); $values = array($resource[$x]['pagetitle'],$summary,$link,$username,strftime($date, $resource[$x][$datetype]),$resource[$x]['id']);
These two arrays are used to replace the field with the correct values at this line:
$output .= str_replace($fields,$values,$tpl);
Now, for TV’s, [*tvname*] in the tpl will be replaced by the tv values from the document that NewsListing is called on.
Hopefully in the future, (hint hint Raymond), someone could manage to get it so that we can use the same automatic replacement functions as in the parser.
But until then.....
function generatePlaceholders($placeholders, $prefix="") { global $modx; if (is_array($placeholders)) { foreach($placeholders as $name=> $value) { $modx->setPlaceholder("$prefix$name", $value); } return true; } return false; }
function parseChunk($chunkName, $chunkArr, $prefix="{", $suffix="}") { if(!is_array($chunkArr)) { return false; } $chunk = $this->getChunk($chunkName); foreach($chunkArr as $key => $value) { $chunk = str_replace($prefix.$key.$suffix, $value, $chunk); } return $chunk; }
You apparently mean the solution would be to call from NewsListing snippet a snippet whose purpose would be to handle the vars replacement. This is the second bit of code you posted. Does it mean do something like add $modx->runSnippet(’Replacement_Snippet’); in the NewsListing snippet ? If so, where do I place this in the NewsListing code ?
Now the first bit of code is something you mean to add in the API for the next release, am I correct ? But here comes the dumb no-php-brain question : where do I insert this additionnal code ? document.parser.class.inc.php ?
$tpl = str_replace("[+action+]",$modx->makeURL($modx->documentIdentifier,"",$ref),$tpl); $tpl = str_replace("[+rememberme+]",(isset($cookieSet) ? 1 : 0),$tpl); $tpl = str_replace("[+username+]",$uid,$tpl); $tpl = str_replace("[+checkbox+]",(isset($cookieSet) ? "checked" : ""),$tpl); $tpl = str_replace("[+logintext+]",$loginText,$tpl); echo $tpl;
function mergePlaceholderContent($content) { preg_match_all('~\[\+(.*?)\+\]~', $content, $matches); $cnt = count($matches[1]); for($i=0; $i<$cnt; $i++) { $v = $this->placeholders[$matches[1][$i]]; if(!isset($v)) unset($matches[0][$i]); // here we'll leave empty placeholders for last. else $replace[$i] = $v; } $content = str_replace($matches[0], $replace, $content); return $content; }