We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 53432
    • 46 Posts
    Would someone please tell me how to get TV values from the results of getIterator? The following does not seem to work:

    <?php
    
    $output = '';
    $resource = $modx->resource;
    $id = $modx->resource->get('id');
    
    $children = $modx->getIterator('modResource',array(
    	'published' => 1,
    	'template' => 16,
    	'parent' => $id
    ));
    
    $output = '<ol>';
    
    foreach ($children as $n => $child) {
    	$output .= '<li>';
    	$output .= 'Title: ' $child->get('pagetitle');
    	$output .= 'ThumbnailImageTV: ' $child->TemplateVarResources['ThumbnailImageTV']->get('value');
    	$output .= '</li>';
    }
    
    $output .= '</ol>';
    
    return $output;
    
    


    I am just trying to retrieve the value of a TV called 'ThumbnailImageTV'
      • 4172
      • 5,888 Posts
      $child->getTVValue('ThumbnailImageTV');
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 53432
        • 46 Posts
        @Bruno17, Thank you!!! That worked!

        For reference and for others the final code is below. This snippet gets published child resources of the current resource that use a certain template. This would be useful for creating a landing page or thumbnail grid of resources.

        <?php
        $output = '';
        $id = $modx->resource->get('id');
        
        $children = $modx->getIterator('modResource',array(
        	'published' => 1,
        	'template' => 16,
        	'parent' => $id
        ));
        
        $output = '<ol>';
        
        foreach ($children as $child) {
        	$output .= '<li>';
        	$output .= 'Title: ' . $child->get('pagetitle');
        	$output .= 'ThumbnailImageTV: ' . $child->getTVValue('ThumbnailImageTV');
        	$output .= '</li>';
        }
        
        $output .= '</ol>';
        
        return $output;