The more and more I play with MODx and PHP, the more I find myself able to do. So I figured that ditto should have this capability, but it doesn’t seem to. Well I hacked it into ditto. I think this makes ditto infinitely more customizable with templates.
What this hack basically does, is allow the document being summarized by ditto to control the template of that summary. As such, you could have an infinite number of templates in ditto now. This is what you have to hack, to allow this.
First in the ditto snippet locate the comment that says "Process information for display." and change:
$output .= $ditto->render($resource[$x], $x, $format, $dateFormatType, $templates, $dateFormat, $debug, $summary, $link, $stop);
TO
$output .= $ditto->render($resource[$x], $x, $format, $dateFormatType, $templates, $dateFormat, $debug, $summary, $link, $stop,$tplTV);
In the ditto.class.inc.php file at around line 166 change:
function render(&$resource, $x, $format, $datetype, $templates, $date, $debug, $summary = "", $link = "", $stop)
TO
function render(&$resource, $x, $format, $datetype, $templates, $date, $debug, $summary = "", $link = "", $stop,$tplTV)
In the ditto.class.inc.php file at around line 214 change:
$currentTPLKey = $this->getCurrentTPL($x, $stop, $resource['id'], $format, $templates);
$currentTPL = $templates["$currentTPLKey"];
$currentTPLname = substr("$currentTPLKey", 3);
TO
$currentTPLKey = $this->getCurrentTPL($x, $stop, $resource['id'], $format, $templates);
$currentTPL = $templates["$currentTPLKey"];
$currentTPLname = substr("$currentTPLKey", 3);
$currentTPLByChunk = $modx->getTemplateVar($tplTV,$fields="*",$resource['id']);
if($modx->getChunk($currentTPLByChunk['value'])) $currentTPL = $modx->getChunk($currentTPLByChunk['value']);
THAT IS IT!
Now just create a template variable in the document that you want to be able to the template for its ditto summary. In that template variable, put the name of the chunk that contains the ditto placeholders.
Example Call with New Parameter:
[!Ditto? &startID=`2` &summarize=`5` &total=`9` &tpl=`m3_ContentUnit` &tplTV=`tplOverride`!]
Now let’s say I place 7 documents in a folder and their template has the TV called tplOverride.
Doc 1 set tplOverride to RedBox
Doc 2 set tplOverride to OrangeBox
Doc 3 set tplOverride to YellowBox
Doc 4 set tplOverride to GreenBox
Doc 5 set tplOverride to BlueBox
Doc 6 set tplOverride to IndigoBox
Doc 7 set tplOverride to VioletBox
Now instead of using the chunk m3_ContentUnit, each document will use its respective chunk (i.e. RedBox, OrangeBox,etc.) If one of those chunks doesn’t exist, then Ditto will fall back to the default template I set, m3_ContentUnit.
WARNING! I just quickly tested this. It might cause some problems outside of my limited testing. If it does, let me know. Also, I am sure there is a more eloquent solution, so feel free to show me how I can be more eloquent of a coder.