<?php
$path = MODX_CORE_PATH . 'components/aeiproducts/';
$result = $modx->addPackage('aeiproducts',$path .
'model/','aei_');
if (! $result) {
return 'failed to add package';
}
$products = $modx->getCollection('Product');
foreach($products as $product) {
$imgName = $product->get('itemno'); // Grab the image name
$imgLink = 'assets/images/prods/' . $imgName . '.jpg'; // Create the full link
$fields = $product->toArray();
$output .= $modx->getChunk('ShowProds', array_merge($fields, array('imgLink'=>$imgLink, 'imgName'=>$imgName)));
}
return $output;
?>This question has been answered by breezer. See the first response.
$imgName = isset($imgName) ? $imgName : $defaultImgName; $imgLink = 'assets/images/prods/' . $imgName . '.jpg'; // Create the full link
Something like this should work...This doesn't work because even if there's no image of a particular itemno, the link still gets created. I might need a way to check in the images folder first, to see if the image is there. I just don't know how.
$imgName = isset($imgName) ? $imgName : $defaultImgName; $imgLink = 'assets/images/prods/' . $imgName . '.jpg'; // Create the full link
$imgName = $product->get('itemno'); // Grab the image name
if (empty($imgName)) {
$output .= $modx->getChunk('ShowProdsNoImage');
} else {
$output .= $modx->getChunk('ShowProds', array_merge($fields, array('imgLink'=>$imgLink, 'imgName'=>$imgName)));
}// set up default image at top of script $default_image ='assets/images/prods/default_image.jpg';
$imgLink = 'assets/images/prods/' . $imgName . '.jpg'; // Create the full link
// if the image does not exist, use default
if( !file_exists( $imgLink ) ){
$imgLink = $default_image;
}
Maybe something like this:Thank you!!
// set up default image at top of script $default_image ='assets/images/prods/default_image.jpg';
then modify the foreach loop
$imgLink = 'assets/images/prods/' . $imgName . '.jpg'; // Create the full link // if the image does not exist, use default if( !file_exists( $imgLink ) ){ $imgLink = $default_image; }