ParseImages snippet for modx

Another modX snippet,
this will grab all the images from a set folder and display them in a chunk




<?php
/*
::::::::::::::::::::::::::::::::::::::::
Snippet name: ParseImages

Description:
parses images in &folder in chunk &tpl
::::::::::::::::::::::::::::::::::::::::
Usage:
[!ParseImages? &tpl=`myChunk_tpl` &folder='assets/images/folder'!]
*/
// $folder;
// $tpl;
$output = "";
$filesArray = Array();

$imgDir = opendir ($folder);

while ( $file = readdir( $imgDir ) )
{
//checks that file is an image
$file_type = strrchr( $file, "." );
$is_image = eregi( "jpg|gif|png",$file_type );

if ( $file != '.' && $file != '..' && $is_image )
{
array_push($filesArray,$file);
}
}

rsort($filesArray);

foreach ($filesArray as &$fn) {

// set the placeholder
$params['image']=$modx->config['site_url'].$folder.$fn;
$params['imagefilename']=$fn;

// Parse the chunk
$output .= $modx->parseDocumentSource($modx->parseChunk($tpl, $params, '[+', '+]'));
}
closedir ($imgDir);

return $output;
?>
Posted on 2010 Feb 03 by Daniel

(optional)

smile wink wassat tongue laughing sad angry crying 


Enter the code shown in the image:


| Forget Me
Content Management Powered by CuteNews