We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19889
    • 616 Posts
    Hello

    I’m using ditto on a folder page to show the latest entry in that folder.

    the child document contains a call to a snippet that lists some images from the server - the call looks like this:
    $id 	= isset($id) ? $id : $modx->documentIdentifier;
    $folder	= 'assets/site/images/properties/'.'p'.$id.'/';

    each child document has it’s own folder on the server - so for instance document 24 has a folder like this: ’p24’;

    When looking at the page on the folder page (id 23), the call fails since the call to the snippet is executed with the id of the parent document (23) instead of the child page id which is 24 that would result in listing the images in the p24 folder on the server.

    Does anybody have an idea how to solve this?

    Thank you in advance for your help.

    maybe I’m a little closer - this is what I have:
    if ($modx->documentObject['isfolder']) {
     return '[+id+]';
    }else{
    $id 	= $modx->documentIdentifier;
    }
    


    the isfolder part returns the correct id of the child document - however I’m unable to do something like this:
    $id = '[+id+]'


      • 10449
      • 956 Posts
      Why even using a snippet? Just write

      assets/site/images/properties/p[+id+]/

      in your Ditto template chunk.
        • 19889
        • 616 Posts
        got a little further:

        the following code seems to work:
        if ($modx->documentObject['isfolder']) {
        	$children= $modx->getActiveChildren( $modx->documentIdentifier, 'createdon', 'DESC');
        	if (!$children === false) {
            	$firstChild= $children[0];
            	$id = $firstChild['id'];
        	}
        } else {
        	$id 	= $modx->documentIdentifier;
        }
        
        $folder	= 'assets/site/images/properties/'.'p'.$id.'/';
        
        //set allowed extensions
        $extList = array();
        $extList['gif']	= 'image/gif';
        $extList['jpg'] 	= 'image/jpeg';
        $extList['jpeg']	= 'image/jpeg';
        $extList['png'] 	= 'image/png';
        
        
        $i = 0;
        $files = array();
        $handle = opendir($folder);
        while ( false !== ( $file = readdir($handle) ) ) {
        	$file_info = pathinfo($file);
        	if (isset( $extList[ strtolower( $file_info['extension'] ) ] )) {
        		$files[$i++] = realpath($file_info['dirname'].'/'.$folder.$file);
        	}
        }
        closedir($handle);
        
        $output = '';
        
        if ($i == 0) {
        	return $output;	
        	die();
        }
        
        $output .= '<div id="thumb-items" class="thumbs">';
        $output .= '	<div id="btn-left" class="thumb-nav"> </div>';
        $output .= '		<div id="thumb-wrapper">';
        $output .= '			<div id="thumb-wrapper-div">';
        $output .= '				<ul id="thumb-list" class="autoclear">';
        				
        
        foreach ($files as &$file) {
        	$output .= '					<li><a class="item" href="assets/site/scripts/phpThumb/phpThumb.php/zc=1;267x200;/'.$file.'"><img src="assets/site/scripts/phpThumb/phpThumb.php/zc=1;120x90;'.$file.'" alt="" width="120" height="90" /></a></li>';
        }
        
        $output .= '				</ul>';
        $output .= '			</div>';
        $output .= '		</div>';
        $output .= '	<div id="btn-right" class="thumb-nav"> </div>';
        $output .= '</div>';
        
        return $output;


        I’m sure there has to be a better way to pass the child document id from the parent folder ditto listing to the snippet?!