We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 41294
    • 34 Posts
    I have used the renderChunk for the first time to have functionality of MIGX inside MIGX.

    I have a formtab json something like this: main MIGX

    [
        {
            "caption": "Work Info",
            "fields": [
                {
                    "field": "title",
                    "caption": "Project Title"
                },
                {
                    "field": "categories",
                    "caption": "Categories",
                    "inputTV": "checkbox"
                },
                {
                    "field": "image",
                    "caption": "Image (900W x 600H)",
                    "inputTV": "image"
                }
            ]
        },
        {
            "caption": "Sub Images",
            "fields": [
                {
                    "field": "subImages",
                    "caption": "Sub Images",
                    "inputTV": "our_works_subimages",
                    "renderer": "this.renderChunk"
                }
            ]
        }
    ]



    Then i have a formtab json something like this: sub MIGX

    [
        {
            "caption": "Sub Images",
            "fields": [
                {
                    "field": "title",
                    "caption": "Title"
                },
                {
                    "field": "subimage",
                    "caption": "Image (900W x 600H)",
                    "inputTV": "subimage"
                }
            ]
        }
    ]



    The chunk render pretty well, but the only problem is the image path is not in the full path for the Sub Images inside sub-MIGX, then image on the main MIGX renders path correctly. The right path is something like this "/folder/images/work/img.jpg", this is the correct path, but the subimage renders path like this "work/img.jpg". I used Media Source for image TV. How can i fix this problem? Thanks ;-)
      • 25506
      • 6 Posts
      If you use MIGX's getImageList snippet, the image URL will be automatically adjusted for your media source. For some reason the image URL from a MIGX image field is not automatically prepended with the media source base URL. This means that if you're using your own snippet, rather than getImageList, you have to adjust the URL yourself. Here's a code fragment from a snippet I created:

      // Get the media source base URL (replace the 2 with your media source id)
      $mediaSource = $modx->getObject('modMediaSource', 2)->get('properties');
      $baseUrl = $mediaSource['baseUrl']['value'];
      
      foreach ($input as $migxRow) {
      	// Prepend the image URL with the media source base URL
      	// MIGX doesn't do this automatically
      	$migxRow['image'] = $baseUrl . $migxRow['image'];
      	$output[] = $modx->getChunk($tpl, $migxRow);
      }