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:
The TPL:
The SNIPPET:
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 '';
Комментарии: 6
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:
Snippet getMyImages:
Now you can use placeholders in chunk:
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.
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.
Works perfect!!! Exactly what I needed!
Thank you!
Thank you!
You can use snippet as modifyer of IMAGE TV
IMAGE_PATH
<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 '';
6 snippets calls instead of 1 in &prepareSnippet.
Only another way for this task. Not best way =)
Thank you for your help also!
I used Василий way and since it works so well I leave that.
I used Василий way and since it works so well I leave that.
Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.