We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 2396
    • 101 Posts
    Hi,

    Scenario: I'm using MIGX to build a media centre and things are going pretty well. However, now the client has made a request which seems really simple but I'm struggling with.

    At the moment I have set up the documents as below, with an images MIGX and a videos MIGX on the respective pages because I need to have images, and video from Vimeo and Youtube, in the media centre, so I have two slightly different MIGXs. The difference is that the image MIGX has the image with a self-generated PhpThumbOf thumbnail, and the video MIGX has an iframe and manually selected thumbnail (they are then both shown in a lightbox).

    Project 1
    - Images (has a mediaCentreImages MIGX)
    - Video (has a mediaCentreVideo MIGX)
    Project 2
    - Images (has a mediaCentreImages MIGX)
    - Video (has a mediaCentreVideo MIGX)
    Project 3 etc...

    They are also under image and video pages so they can be tagged (by project, region, market and media type) and filtered using AdvSearch Query Hooks, and everything works - everything works and filters perfectly.

    Problem: Now the client would like to show just 5 media results for each project, on another page, and this would ideally be a random selection of media items from each project, (images and video). Because they are in separate MIGXs, I can't get them to merge and display together, limited to 5, and with a random combination of media types.

    The MIGX's are:

    [
    {"caption":"Add Media", "fields": [
    {"field":"title","caption":"Title","description":"mediaTitle"},  {"field":"description","caption":"Description","description":"mediaDescription"}, 
    {"field":"image","caption":"Image","inputTV":"mediaImage"},
    {"field":"date","caption":"Date","inputTV":"mediaDate"} 
    ]}
    ]
    
    [
    {"header": "Title", "width": "160", "sortable": "true", "dataIndex": "title"},
    {"header": "Description", "width": "160", "sortable": "true", "dataIndex": "description"},  
    {"header": "Image", "width": "50", "sortable": "false", "dataIndex": "image","renderer": "this.renderImage"},
    {"header": "Date", "width": "160", "sortable": "true", "dataIndex": "date"}
    ]
    
    [[!getImageList?
    	&tvname=`mediaCentreImages`
    	&tpl=`mediacentreImage`
    	&docid=`[[+id]]`
    ]]


    and

    [
    {"caption":"Add Media", "fields": [
    {"field":"title","caption":"Title","description":"mediaTitle"},  {"field":"description","caption":"Description","description":"mediaDescription"},
    {"field":"embed","caption":"Embed","description":"mediaEmbed"},
    {"field":"image","caption":"Image","inputTV":"mediaImage"},
    {"field":"date","caption":"Date","inputTV":"mediaDate"}
    ]}
    ]
    
    [
    {"header": "Title", "width": "160", "sortable": "true", "dataIndex": "title"},
    {"header": "Description", "width": "160", "sortable": "true", "dataIndex": "description"},
    {"header": "Embed", "width": "160", "sortable": "true", "dataIndex": "embed"},  
    {"header": "Image", "width": "50", "sortable": "false", "dataIndex": "image","renderer": "this.renderImage"},
    {"header": "Date", "width": "160", "sortable": "true", "dataIndex": "date"}
    ]
    
    [[!getImageList?
    	&tvname=`mediaCentreVideos`
    	&tpl=`mediacentreVideo`
    	&docid=`[[+id]]`
    ]]


    I know the below is gobbledygook and doesn't work, but this is basically what I would like to do – so far I can't work out a way to get what I want using getResources:

    [[!getImageList?
    	&tvname=`mediaCentreImages,mediaCentreVideos`
    	&tpl=`mediacentreImage,mediacentreVideo`
    	&docid=`[[+id]]`
    	&limit=`5`
    	&sortby=`RAND()`
    ]]


    Is there a way to merge or join the MIGX items' output so I can then take just the first 5?

    (I hope that makes sense : ) Thanks in advance. [ed. note: atype last edited this post 12 years, 6 months ago.]
      • 4172
      • 5,888 Posts
      try this snippet (untested)

      <?php
      
      //[[combineJsons? &json1=`[[+tv.migx1]]` &json2=`[[+tv.migx2]]` &tpls=`tpl1,tpl2`]]
       
      $jsons = array();
      $jsons[] = $modx->getOption('json1', $scriptProperties, '');
      $jsons[] = $modx->getOption('json2', $scriptProperties, '');
       
      $tpls = explode(',', $modx->getOption('tpls', $scriptProperties, ''));
       
      //combine jsons and add tpl to each item
      $output = array();
      $i = 1;
      foreach ($jsons as $key => $json) {
          $items = $modx->fromJson($json);
          if (is_array($items)) {
              foreach ($items as $item) {
                  $item['tpl'] = $tpls[$key];
                  $item['MIGX_id'] = $i;
                  $output[] = $item;
                  $i++;            
              }
              
          }
      }
       
      return $modx->toJson($output);
      
      


      use it this way:

      [[!getImageList?
          &value=`[[combineJsons? &json1=`[[+tv.mediaCentreImages]]` &json2=`[[+tv.mediaCentreVideos]]` &tpls=`mediacentreImage,mediacentreVideo`]]`
          &tpl=`@FIELD:tpl`
          &limit=`5`
          &randomize=`1`
      ]]
      [ed. note: Bruno17 last edited this post 12 years, 6 months ago.]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 2396
        • 101 Posts
        Bruno has been helping me out with this and the above snippet works together with another he cooked up for my setup. I have to say, MODX is a truly amazing thing, and MIGX has opened my eyes too.

        Thanks Bruno, I'll buy you a beer!
          • 51216
          • 35 Posts
          Hi Bruno

          I am new to modx and I'm trying to get multiple migx tv's to display using one tpl.

          <?php
          //[[combineJsons? &json1=`[[+tv.migx1]]` &json2=`[[+tv.migx2]]` &tpls=`tpl1,tpl2`]]
            
          $jsons = array();
          $jsons[] = $modx->getOption('json1', $scriptProperties, '');
          $jsons[] = $modx->getOption('json2', $scriptProperties, '');
            
          $tpls = explode(',', $modx->getOption('tpls', $scriptProperties, ''));
            
          //combine jsons and add tpl to each item
          $output = array();
          $i = 1;
          foreach ($jsons as $key => $json) {
              $items = $modx->fromJson($json);
              if (is_array($items)) {
                  foreach ($items as $item) {
                      $item['tpl'] = $tpls[$key];
                      $item['MIGX_id'] = $i;
                      $output[] = $item;
                      $i++;            
                  }
                   
              }
          }
            
          return $modx->toJson($output);
          

          and
          [[!getImageList? 
              &value=`[[combineJsons? &json1=`[[+tv.SecurityAlertsTV]]` &json2=`[[+tv.NewslettersTV]]` &tpls=`homeNewsTpl`]]`
              &tpl=`@FIELD:tpl`
              &limit=`5`
              &randomize=`1`
          ]]
          


          This doesn't work.
          Do you have any suggestions?
            • 4172
            • 5,888 Posts
            Doesn't look that bad to me.
            What does your snippet return. Example - Output?
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!