Hm after thinking about my code, i realized that the $modx->documentObject[’id’] call, might cause a problem. I think this won’t return the desired results when called inside ditto... simply because it will (probably) use the id of the Document that executes the ditto call, instead of the Document that provides content for ditto.
Thus, you’ll have to set the ID manually. Here is what i suggest:
<?php
/**
* Convert a text with linebreaks to a html list
*/
$chunk = isset($chunk) ? $chunk : false;
$tv = isset($tv) ? $tv : false;
$delimiter = isset($delimiter) ? $delimiter : "\n";
$docid = isset($docid) ? $docid : $modx->documentObject['id'];
if($tv){
$tvArray = $modx->getTemplateVarOutput(array($tv), $docid);
if(!$tvArray[$tv])
return;
$text = $tvArray[$tv];
} else if($chunk){
$text = $modx->getChunk($chunk);
if(!$text)
return;
} else {
return;
}
$lines = explode($delimiter, $text);
$out = '<ul>';
foreach($lines as $line){
$out .= '<li>' . trim($line) . '</li>';
}
$out .= '</ul>';
return $out;
?>
The above snippet now has a fourth parameter called &docid which allows you to specify the desired document id (this should point to the document, that has the TV called ’listItems’). If none is specified, it will use the id of the documentObject (which is not what you want when using ditto)!
Now you call it in your Ditto Template as following:
[[ListBuilder? &tv=`listItems` &docid=`[+id+]`]]