Here is a new version of the code posted above
it should work for any snippet call within a ditto tpl
here are some test results
With 198 documents
Ditto call
[!ditto? &parents=`0` &tpl=`photolist` &summarize=`198` &depth=`4` &paginate=`1` &limit=`200` &filter=`isfolder,1,2` !]
with
[[GetField? &id=`[+parent+]` &field=`pagetitle` ]]
MySQL: 1.6104 s, 413 request(s)
with
[[SSR? &ph_ID=`[+parent+]` &phName=`ditto_parent_name` &snippetName=`GetField` &snippetParams=`docid:[+parent+]|field:pagetitle` ]]
MySQL: 1.6374 s, 216 request(s)
SSR code
<?php
/*
SSR : StoreSnippetResult
Author : heliotrope
Description:
Execute snippet from ditto and store the value in modx placeholders
Reduce the amount of db queries
Sample call for getField
[[GetField? &id=`[+parent+]` &field=`pagetitle` ]]
becomes
[[SSR? &ph_ID=`[+parent+]` &phName=`ditto_parent_name` &snippetName=`GetField` &snippetParams=`id:[+parent+]|field:pagetitle` ]]
*/
$ph_ID = (isset($ph_ID) ) ? $ph_ID : false;
$phName = (isset($phName)) ? $phName: "SSR_";
$sName = (isset($sName)) ? $sName: false;
$ditto_ID = (isset($dittoID)) ? $ditto_ID : '';
//snippetParams=`id:id_value|field:field_value`
$snippetParams = (isset($snippetParams)) ? $snippetParams : false ;
if(!$ph_ID) return "Missing ph_ID";
if(!$sName) return "Missing Snippet Name";
if(!$snippetParams) return "Missing Snippet Params";
$modxPH = $dittoID . $phName . $ph_ID;
$ph_value = $modx->getPlaceholder($modxPH);
if(isset($ph_value)){
$s_output = $ph_value;
}else{
$gParams = explode('|', $snippetParams);
$sParams = array();
foreach($gParams as $params){
$paramV = explode(':',$params);
$sParams[$paramV[0]] = $paramV[1];
}
$s_output = $modx->runSnippet($sName,$sParams);
$modx->setPlaceholder($modxPH, $s_output);
}
return $s_output;
?>