Issue with Thumbnail image in pagelist

Permalink
I have created a custom template for the page_list block and all I have changed is to uncomment out the code which will display thumbnail images.

I have added a custom attribute to the page type called 'thumbnail' and each of the pages included in my page-list block have a thumbnail image assigned to them.

But as soon as I uncomment this line the page doesn't render from there down;

$thumb = $ih->getThumbnail($img, 100, 9999, false);


These are all of the lines of code I have uncommented in the block view.php (copied to my custom template folder under blocks), and I have narrowed it down to this line with some testing.

$ih = Loader::helper('image'); 
....
if($page->getAttribute('thumbnail')) {
         $img = $page->getAttribute('thumbnail');
         $thumb = $ih->getThumbnail($img, 100, 9999, false);
      }
....
<img src="<?php  echo $thumb->src ?>" width="<?php  echo $thumb->width ?>" height="<?php  echo $thumb->height ?>" alt="" />

 
irsah replied on at Permalink Reply
irsah
Hi Martin,

You're almost there. instead of the if{...} , relocate the line of codes within the <?php foreach ($pages as $page); ...... codes. without the "if{}".

Looks something like this
foreach ($pages as $page):
// Prepare data for each page being listed...
$title = $th->entities($page->getCollectionName());
...codes...
$img = $page->getAttribute('thumbnail');
$thumb = .....
...more codes....


Img output after the HTML line stated in the file.

*edit* if you have uncomment the img helper top above lines in the file is should work :)

Hope it helps.
Irsah
MartinaL replied on at Permalink Reply
It already is, this was just a snippet of the code, here is the whole file

<?php 
defined('C5_EXECUTE') or die("Access Denied.");
$rssUrl = $showRss ? $controller->getRssUrl($b) : '';
$th = Loader::helper('text');
$ih = Loader::helper('image'); //<--uncomment this line if displaying image attributes (see below)
//Note that $nh (navigation helper) is already loaded for us by the controller (for legacy reasons)
?>
<div class="ccm-page-list">
   <?php  foreach ($pages as $page):
      // Prepare data for each page being listed...
      $title = $th->entities($page->getCollectionName());
      $url = $nh->getLinkToCollection($page);
      $target = ($page->getCollectionPointerExternalLink() != '' && $page->openCollectionPointerExternalLinkInNewWindow()) ? '_blank' : $page->getAttribute('nav_target');
      $target = empty($target) ? '_self' : $target;
      $description = $page->getCollectionDescription();
irsah replied on at Permalink Reply
irsah
Remove the "if()" like i mentioned above... just add in the code like the example...

refer code to remove lines..

...code...
$description = $controller->truncateSummaries ? $th->shorten($description, $controller->truncateChars) : $description;
$description = $th->entities($description);
 if($page->getAttribute('thumbnail')) {  <--remove this line
         $img = $page->getAttribute('thumbnail');
         $thumb = $ih->getThumbnail($img, 100, 9999, false);
      }    <--remove this line
...more code....
ScottSandbakken replied on at Permalink Reply
ScottSandbakken
You should grab the image attribute, then test that you have an image before you attempt to create the thumbnail.

...code...
$description = $controller->truncateSummaries ? $th->shorten($description, $controller->truncateChars) : $description;
$description = $th->entities($description);
$img = $page->getAttribute('thumbnail'); // Grab the image
 if(isset($img)) { // Make sure you have an image
         $thumb = $ih->getThumbnail($img, 100, 9999, false); // Create the thumbnail
      } 
...more code....


When you output the image, be sure to check that the $thumb var is set.

if(isset($thumb)) {
     <img src="<?php echo $thumb->src ?>" width="<?php echo $thumb->width ?>" height="<?php echo $thumb->height ?>" alt="" />
}
irsah replied on at Permalink Reply
irsah
Hey Netjunky,

Thanks for the heads up.

More detail there, but I used the codes form the core pagelist file and works, with or without image/thumbnails assigned to it. Only drawback is the empty square if a page has no images set.

Your explanation led me to another glitch I had with an custom image block, thanks for the insights.

Regards.
ScottSandbakken replied on at Permalink Reply
ScottSandbakken
Add the thumbnail attribute to the home page, then grab it from there as a default image if none is set on the current page.

//...code...
$description = $controller->truncateSummaries ? $th->shorten($description, $controller->truncateChars) : $description;
$description = $th->entities($description);
$img = $page->getAttribute('thumbnail'); // Grab the image
if (!isset($img)) {
   // No image set, grab the default from the home page
   $home = Page::getById(HOME_CID);
   $img = $home->getAttribute('thumbnail');
}
 if(isset($img)) { // Make sure you have an image
         $thumb = $ih->getThumbnail($img, 100, 9999, false); // Create the thumbnail
      } 
//...more code....


When you output the image, set an empy div that you can style. This will only be used if neither the current page nor the home have the thumbnail attribute set.

if(isset($thumb)) {
     <img src="<?php echo $thumb->src ?>" width="<?php echo $thumb->width ?>" height="<?php echo $thumb->height ?>" alt="" />
} else {
   <div class="no-image" style="width:100px;height:100px;background-color:#cacaca;"></div>
}
foster replied on at Permalink Reply
foster
I was running into a different problem than the OP, but this snippet really helped me out. Thanks NetJunky279!
MartinaL replied on at Permalink Reply
Tried this irsah and it made no difference :(

NetJunky279, also tried what you suggested and it made no difference either sorry
irsah replied on at Permalink Reply
irsah
Hmm.. kind of weird???

Other options can think of would be:
1. Permissions for blocks, pages, editing, files and files manager, images etc.
2. Location of stored files in system and setting Files Location.
3. The publichtml/files folder permission in your host account has chmod 755 (read and execute) if not try chmod 777 for images/cache files.
4. Page edit mode > select block > template > the name of template created = same name as the folder created in public_html/blocks/page_list/templates/your_template_name/
5. Cache setting turned off. Clear files cache and the working browser cache.
6. Attribute handle for pagetype thumbnail = attribute type image > attribute handle name (small caps with underscore for spaces).
7. Hotlinking setting turned on in domain control panel ???? Doubt this but how knows?? You can also check thru your domain .htaccess file with any changes (if you are familiar with)

Those are my checklist if some of my users have the problems.

Here's a working page_list with thumbnails from your given code which uses the codes i've given (top sample) and NetJuncky's codes (bottom sample)http://development.irsah.com/test-pages/...