From 5baecc82911ad296d5c167c677a591ac8a948bd4 Mon Sep 17 00:00:00 2001 From: Bruno Perner Date: Thu, 22 Sep 2011 07:38:31 +0200 Subject: [PATCH 1/2] added property toJsonPlaceholder for reusing the fetched resources in different ways by other snippets Signed-off-by: Bruno Perner --- core/components/getresources/snippet.getresources.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/components/getresources/snippet.getresources.php b/core/components/getresources/snippet.getresources.php index 9e6a957..75f8352 100644 --- a/core/components/getresources/snippet.getresources.php +++ b/core/components/getresources/snippet.getresources.php @@ -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(); @@ -394,6 +396,11 @@ ,$includeContent ? $resource->toArray() : $resource->get($fields) ,$tvs ); +$toJsonPlaceholder = $modx->getOption('toJsonPlaceholder', $scriptProperties, false); +if ($toJsonPlaceholder) { + $modx->setPlaceholder($toJsonPlaceholder, $modx->toJson($properties)); + return ''; +} $resourceTpl = ''; $tplidx = 'tpl_' . $idx; if (!empty($$tplidx)) $resourceTpl = parseTpl($$tplidx, $properties); From 1e26a68de019febd3c737197ea0c4fb67f910a0b Mon Sep 17 00:00:00 2001 From: Bruno Perner Date: Thu, 22 Sep 2011 07:47:57 +0200 Subject: [PATCH 2/2] fixed last commit - toJsonPlaceholder Signed-off-by: Bruno Perner --- .../getresources/snippet.getresources.php | 53 ++++++++++--------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/core/components/getresources/snippet.getresources.php b/core/components/getresources/snippet.getresources.php index 75f8352..6d3b68b 100644 --- a/core/components/getresources/snippet.getresources.php +++ b/core/components/getresources/snippet.getresources.php @@ -396,35 +396,40 @@ ,$includeContent ? $resource->toArray() : $resource->get($fields) ,$tvs ); -$toJsonPlaceholder = $modx->getOption('toJsonPlaceholder', $scriptProperties, false); -if ($toJsonPlaceholder) { - $modx->setPlaceholder($toJsonPlaceholder, $modx->toJson($properties)); - return ''; -} - $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(), '
' . print_r($properties, true) .'
'); - } 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(), '
' . print_r($properties, true) .'
'); + } 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);