Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 31 additions & 19 deletions core/components/getresources/snippet.getresources.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
* last - (Opt) Define the idx which represents the last resource (see tplLast) [default=# of
* resources being summarized + first - 1]
* outputSeparator - (Opt) An optional string to separate each tpl instance [default="\n"]
* toJsonPlaceholder - (Opt) Outputs all fetched resources/fields as Json-string to specified placeholder for
* reusing and modifying the output in different ways by other snippets.
*
*/
$output = array();
Expand Down Expand Up @@ -394,30 +396,40 @@
,$includeContent ? $resource->toArray() : $resource->get($fields)
,$tvs
);
$resourceTpl = '';
$tplidx = 'tpl_' . $idx;
if (!empty($$tplidx)) $resourceTpl = parseTpl($$tplidx, $properties);
switch ($idx) {
case $first:
if (!empty($tplFirst)) $resourceTpl = parseTpl($tplFirst, $properties);
break;
case $last:
if (!empty($tplLast)) $resourceTpl = parseTpl($tplLast, $properties);
break;
}
if ($odd && empty($resourceTpl) && !empty($tplOdd)) $resourceTpl = parseTpl($tplOdd, $properties);
if (!empty($tpl) && empty($resourceTpl)) $resourceTpl = parseTpl($tpl, $properties);
if (empty($resourceTpl)) {
$chunk = $modx->newObject('modChunk');
$chunk->setCacheable(false);
$output[]= $chunk->process(array(), '<pre>' . print_r($properties, true) .'</pre>');
} else {
$output[]= $resourceTpl;
if ($toJsonPlaceholder) {
$output[] = $properties;
}else{
$resourceTpl = '';
$tplidx = 'tpl_' . $idx;
if (!empty($$tplidx)) $resourceTpl = parseTpl($$tplidx, $properties);
switch ($idx) {
case $first:
if (!empty($tplFirst)) $resourceTpl = parseTpl($tplFirst, $properties);
break;
case $last:
if (!empty($tplLast)) $resourceTpl = parseTpl($tplLast, $properties);
break;
}
if ($odd && empty($resourceTpl) && !empty($tplOdd)) $resourceTpl = parseTpl($tplOdd, $properties);
if (!empty($tpl) && empty($resourceTpl)) $resourceTpl = parseTpl($tpl, $properties);
if (empty($resourceTpl)) {
$chunk = $modx->newObject('modChunk');
$chunk->setCacheable(false);
$output[]= $chunk->process(array(), '<pre>' . print_r($properties, true) .'</pre>');
} else {
$output[]= $resourceTpl;
}
}
$idx++;
}

/* output */
$toJsonPlaceholder = $modx->getOption('toJsonPlaceholder', $scriptProperties, false);
if ($toJsonPlaceholder) {
$modx->setPlaceholder($toJsonPlaceholder, $modx->toJson($output));
return '';
}

$toSeparatePlaceholders = $modx->getOption('toSeparatePlaceholders',$scriptProperties,false);
if (!empty($toSeparatePlaceholders)) {
$modx->setPlaceholders($output,$toSeparatePlaceholders);
Expand Down