getResources not working properly with snippet

I use getResources along a tpl that includes a snippet. Problem is that getresources gives mixed/wrong results.

My getResource call:
[[!getPage?
&elementClass=`modSnippet`
&element=`getResources`
&parents=`219`
&cache=`false`
&tpl=`MATCH_INDEX_FREE_TPL`
&showUnpublished=`0`
&showHidden=`1`
&includeContent=`1`
&limit=`5`
&processTVs=`1`
&includeTVs=`1`
&depth=`25`
&sortby=`createdon`
&sortdir=`DESC`
&pageNavVar=`page.nav`
]]


The TPL:
[[!IMAGE_PATH? &docid=`[[+id]]`]]
<div class="dog_cont">
<div class="data_title_new">[[+tv.Race]]</div>
<div class="dog_photo2">
<div id="ad_image_big"><a href="[[!+path1:phpthumbof=`w=900&zc=t`]]" rel="lightbox"><img src="[[!+path1:phpthumbof=`w=200&h=160&zc=t`]]" /></a></div>
<div id="ad_image_small" ><a href="[[!+path2:phpthumbof=`w=900&zc=t`]]" rel="lightbox"><img src="[[!+path2:phpthumbof=`w=95&h=80&zc=t`]]" /></a></div>
<div id="ad_image_small2"><a href="[[!+path3:phpthumbof=`w=900&zc=t`]]" rel="lightbox"><img src="[[!+path3:phpthumbof=`w=95&h=80&zc=t`]]" /></a></div>
</div>


The SNIPPET:
<?php
$docid = $modx->getOption('docid',$scriptProperties,$modx->resource->get('id'));
if ($resource = $modx->getObject('modResource',$docid)){
    $values = explode(',',$resource->getTVValue('IMAGE'));
    $i = 1;
    foreach ($values as $value){
        $modx->setPlaceholder('path'.$i,$value);
        $i++;
    }    
}
return '';
Poko Loko
11 февраля 2016, 23:00
modx.pro
2 538
0

Комментарии: 6

Василий Наумкин
12 февраля 2016, 06:51
+3
You do it wrong. You need to use 3 TVs with type «image» with correct paths to files.

Or you could try to use pdoResources with &prepareSnippet that will additionally process each row:
[[!pdoPage?
	&element=`pdoResources`
	&parents=`219`
	&tpl=`MATCH_INDEX_FREE_TPL`
	&showUnpublished=`0`
	&showHidden=`1`
	&limit=`5`
	&processTVs=`1`
	&includeTVs=`IMAGE,Race`
	&depth=`25`
	&sortby=`createdon`
	&sortdir=`DESC`
	&prepareSnippet=`getMyImages`
]]
[[!+page.nav]]

Snippet getMyImages:
<?php
// $row - is the array with resource selected by pdoResources being processed now
$values = explode(',', $row['tv.IMAGE']); // Your selected TV with images
foreach ($values as $k => $value) {
	$row['path' . ($k +1)] = $value; // Add new placeholders to $row
}
return json_encode($row); // Return data with additional placeholders

Now you can use placeholders in chunk:
<div class="dog_cont">
	<div class="data_title_new">[[+tv.Race]]</div>
	<div class="dog_photo2">
		<div id="ad_image_big">
			<a href="[[+path1:phpthumbof=`w=900&zc=t`]]" rel="lightbox"><img src="[[+path1:phpthumbof=`w=200&h=160&zc=t`]]" /></a>
		</div>
		<div id="ad_image_small" >
			<a href="[[+path2:phpthumbof=`w=900&zc=t`]]" rel="lightbox"><img src="[[+path2:phpthumbof=`w=95&h=80&zc=t`]]" /></a>
		</div>
		<div id="ad_image_small2">
			<a href="[[+path3:phpthumbof=`w=900&zc=t`]]" rel="lightbox"><img src="[[+path3:phpthumbof=`w=95&h=80&zc=t`]]" /></a>
		</div>
	</div>
</div>
No need to make them uncacheable, by the way.

There could be a misunderstanding with letters case of your placeholders, but you can see them all if you will specify a blank &tpl=`` property.

pdoPage and pdoResources is the parts of pdoTools package.
    Poko Loko
    13 февраля 2016, 10:48
    +2
    Works perfect!!! Exactly what I needed!

    Thank you!
    Илья Уткин
    12 февраля 2016, 13:37
    +1
    You can use snippet as modifyer of IMAGE TV
    <div class="dog_cont">
    <div class="data_title_new">[[+tv.Race]]</div>
    <div class="dog_photo2">
    <div id="ad_image_big"><a href="[[+tv.IMAGE:IMAGE_PATH=`1`:phpthumbof=`w=900&zc=t`]]" rel="lightbox"><img src="[[+tv.IMAGE:IMAGE_PATH=`1`:phpthumbof=`w=200&h=160&zc=t`]]" /></a></div>
    <div id="ad_image_small" ><a href="[[+tv.IMAGE:IMAGE_PATH=`2`:phpthumbof=`w=900&zc=t`]]" rel="lightbox"><img src="[[+tv.IMAGE:IMAGE_PATH=`2`:phpthumbof=`w=95&h=80&zc=t`]]" /></a></div>
    <div id="ad_image_small2"><a href="[[+tv.IMAGE:IMAGE_PATH=`3`:phpthumbof=`w=900&zc=t`]]" rel="lightbox"><img src="[[+tv.IMAGE:IMAGE_PATH=`3`:phpthumbof=`w=95&h=80&zc=t`]]" /></a></div>
    </div>

    IMAGE_PATH
    if (!$input) return '';
    if (!$options) $options = 1;
    $values = explode(',',$input);
    if (isset($values[($options - 1)])) {
      return $values[($options - 1)];
    }
    return '';
      Василий Наумкин
      12 февраля 2016, 13:43
      +1
      6 snippets calls instead of 1 in &prepareSnippet.
        Илья Уткин
        12 февраля 2016, 13:49
        +1
        Only another way for this task. Not best way =)
        Poko Loko
        13 февраля 2016, 11:03
        +1
        Thank you for your help also!
        I used Василий way and since it works so well I leave that.

        Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.
        6