pepebe
4/24/2012 - 9:23 PM

MODx: Combining MIGX and Template Variables in MOD Revo

MODx: Combining MIGX and Template Variables in MOD Revo

Source: http://www.unchi.co.uk/2011/06/14/combining-migx-and-template-variables-in-mod-revo/
BY KEIRON – 14/06/2011

Scenario: I have a Template Variable on a page(id 13) called ImageGrid that I need to call from other page(s) but only show some of the content. I will choose which rows using a another Template Variable called WorkThumbs.

ImageGrid

I won't run through how to build this yet, but I use getImageList for the response.

WorkThumbs

Input Type:
Input Option Values: @EVAL return $modx->runSnippet('SelectWork');
Output Type: Delimiter
Delimiter: ,

SelectWork

$q = "SELECT value FROM modx_site_tmplvar_contentvalues WHERE id='502'";
$query = new xPDOCriteria($modx, $q);
if ($query->stmt && $query->stmt->execute()){
while($row = $query->stmt->fetch(PDO::FETCH_ASSOC)) {
$all = json_decode($row['value']);
}
}
$options = ";
foreach($all as $var => $value)
{
$document = $modx->getObject('modResource',array('id' => $all[$var]->link));
$options .= $document->get('pagetitle').'=='.$all[$var]->link.'||';
}
return substr($options, 0, -2);

Snippet Call

[[!getImageList?&tvname=`ImageGrid`&tpl=`thumbTpl`&where=`{"link:in":"[[*WorkThumbs]]"}`&docid=`13`]]

thumbTpl

<div><a href="[[~[[+link]]]]" title="[[+text]]"><img src="[[+image]]" rel="[[+rollover]]" alt="[[+text]]" /></a></div>