500 Internal Server Error with Page Attribute

Permalink
In one of my page types, I'm calling for a page attribute (Image/File) so I can size it and place it on the page.

Here is how I am calling the attribute:

<?php
   $ih = Loader::helper('image');
   $p = $c->getCurrentPage();
   $img = $p->getAttribute('news_image');
   if(isset($img)) {
   $thumb = $ih->getThumbnail($img, 320, 9999);
   }
?>


Later in my template, I am placing the image on the page with this:

<?php if(isset($img)) { ?>
    <div class="news-image">
    <img src="<?php echo $thumb->src ?>" width="<?php echo $thumb->width ?>" height="<?php echo $thumb->height ?>" alt="<?php echo $title ?>" />
    </div>
    <?php } ?>


What I've discovered is that if a page doesn't have that attribute attached to it or if it is attached, but no image is define, that page returns a 500 Internal Server Error and the page stops rendering at the point where the image should be placed.

I'm not sure how to fix this.

Any help would be greatly appreciated.

Thanks!

leinteractive
 
leinteractive replied on at Permalink Reply
leinteractive
Sorry to bump my own thread...anyone have any idea why my code is breaking the site on pages without an Image Attribute selected?