Perhaps I have missed a simpler solution, but this is how I merge a dozen MIGx grids into a single grid.
1. Get the JSON content of all grids with getresources:
[[!getResources?
&parents=`21`
&tpl=`@INLINE [[+MIGx - Items]]`
&includeTVs=`1`
&processTVs=`1`
&tvPrefix=``
&showUnpublished=`1`
&showHidden=`1`
&limit=`99`
&toPlaceholder=`items`
&sortby=`menuindex`
&sortdir=`ASC`
]]
Now we have the JSON content of several grids inside a single chunk. Before we can further process these values we have to stich them together and give each result a unique id.
2. Use the mergeJSON Snippet to fix things.
<?php
// mergeJSON Snippet:
// Usage: [[mergeJSON? &json=`[[+items]]` ]]
$fixJSON = !empty($json) ? $json : "";
// Remove carriage returns and line-breaks
$fixJSON = str_replace( array("\r\n", "\r", "\n"), ' ', $fixJSON );
// Stich individual JSON strings together by replaceing "] "[ with ","
$fixJSON = str_replace( array("] [") , "," , $fixJSON);
// Convert JSON into array
$decode = json_decode($fixJSON,true);
// Overwrite MIGS_id with unique numbers
if(is_array($decode)) {
$MIGX_id = 0;
foreach($decode as $key => $value) {
$MIGX_id = $MIGX_id + 1;
$decode[$key][MIGX_id] = $MIGX_id;
}
// Convert array to JSON string and return result
return json_encode($decode);
}
else {return;}
After we have fixed our JSON code, we can move on.
3. Now we use getImageList to output the whole thing. Instead of docid and tv name we use the value parameter to pass the JSON code returned by mergeJSON.
[[!getImageList?
&value=`[[mergeJSON? &json=`[[+items]]` ]]`
&where=`{ "name:=" : "Ajax" }`
&tpl=`MIGx items tpl`
&sortBy=`name`
&sortDir=`ASC`
]]
Note: sortyBy and sortDir are custome features I have added to my personal getImageList snippet. They are not available for the standard snippet.
[ed. note: pepebe last edited this post 14 years, 5 months ago.]