Quote from: sottwell at Jul 07, 2009, 07:04 PM
No, you would use $modx->setPlaceholder($key, $value) in your loop. Actually, you shouldn’t need to use the mergePlaceholders function at all; MODx will take care of that as part of the document processing.
I understand this part. But in my code i will be returning possibly 100’s of results...by setting the placeholder and then letting MODx parse them seems like overkill since I would need 100’s of placeholders...or am I missing something?
I was hoping to parse the placeholders during each iteration so that the output would already be ’parsed’. I notice that some snippets will add a key to the placeholder like $modx->setPlaceholder($key.’-’.$iteration, $value) so that the resulting placeholder is actually [+name-123+]...this would work. But won’t this add extra, unnecessary overhead to the document parsing (and result in 100’s of items in the placeholders array)? Seems like outputting the direct output would be more economic on the resources.
I have also seen snippets use 3rd party parsers, for example there is a snippet that uses the codeigniter template parser
http://codeigniter.com/user_guide/libraries/parser.html for this.
Am I over complicating this?
I think this is the code Ditto uses to parse the placeholders:
// ---------------------------------------------------
// Function: replace
// Replcae placeholders with their values
// ---------------------------------------------------
function replace( $placeholders, $tpl ) {
$keys = array();
$values = array();
foreach ($placeholders as $key=>$value) {
$keys[] = '[+'.$key.'+]';
$values[] = $value;
}
return str_replace($keys,$values,$tpl);
}
But I don’t understand it...or how to use it
Wayfinder also uses arrays and str_replace for this...
//Process the row
$output .= str_replace($usePlaceholders,$phArray,$useChunk);
//Return the row
return $output . $this->_config['nl'];