Hi,
I met the same problem with a blog system : I wanted to display in the start page a block in which there is the 5 last news [[*introtext]] with a little thumbnail, which was a TV managed by MIGX.
I used : Collection, MIGX (getImageList snippet and dynamic Mediasource as explained in the documentation) and getResources !
I had the same result as mentionned upper : the first row was the introtext with the good image. But the others rows couldn't display the good image. When I watched the path to the image, the entire path was good but the resource ID. The resource ID for every path was the ID of the first row...
After few hours, I decided to change getResources to pdoResources and that worked, with a little snippet of my own to simplify MIGX's getImageList snippet. I guess this is optionnal but I didn't test back with as it was working as expected.
Here's my schema :
-> my resource 55 : display results
--> pdoResources snippet : query the data
---> ArticlesThumb chunk : display every row
----> getJsonList snippet : transform TV json in array Php
-----> thumbTpl chunk : only for the image
You can see all these are nested !
Here are my chunk and snippet if it can help !
The snippet getJsonList
<?php
/**
*
* Return TV JSON values in tpl
*
*
* [[getJsonList?
* &docid=`99` -- ID of ressource where there is the TV. ([[+id]], or 99)
* &tvname=`mytv` -- Name of the TV created with MIGX
* &tpl=`mytpl` -- name of tpl
* ]]
*
*
*
**/
$output ='';
/* Let's get the snippet properties */
$tpl = $modx->getOption('tpl', $scriptProperties);
$docid = $modx->getOption('docid', $scriptProperties);
$tvname = $modx->getOption('tvname', $scriptProperties);
if (empty($docid) or empty($tvname)) {
return '<!-- docid or tvname empty -->';
}
/* Let's get the resource now */
$resource = $modx->getObject('modResource',array('id'=> $docid));
/* and the TV JSON */
$strJSON = $resource->getTVValue($tvname);
/* let's transform JSON in array */
$array = $modx->fromJSON($strJSON);
/* let's process the array */
foreach($array as $result)
{
// print_r($arrJSON); //debug
$image = $result[image];
$title = $result[title];
$description = $result[description];
}
/* send the values in tpl definied in properties */
$output = $modx->getChunk($tpl,array(
'image' => $image,
'title' => $title,
'description' => $description,
));
return $output;
thumbTpl : The chunk tpl in which the image is rendered
<img src="path/to/my/media/[[+id]]/[[+image]]" title="[[+title:default=`[[+image]]`]]" alt="[[+image]]"/>
ArticlesThumb : The chunk row where the image and the text are get
<h2><a href="[[~[[+id]]]]">[[+pagetitle]]</a></h2>
[[getJsonList?
&tvname=`thumb`
&docid = `[[+id]]`
&tpl=`thumbTpl`]]
[[+introtext:striptags:ellipsis=`300`:default=`[[+content:striptags:ellipsis=`160`]]`]]
Call this in the page you want the result :
[[pdoResources?
&parents=`55`
&depth=`0`
&showHidden=`1`
&limit=`3`
&tpl=`ArticlesThumb`
&includeTVs=`thumb` ]]
Hope it's enough clear and it can help. You can and the snippet in MIGX if you want !
PS : MIGX is really a must have for MODX as it is really brillant !!! Thanks Bruno17 !