Empty Image Attribute

Permalink
I've added an image attribute to the blog_entry page type, but if I don't add an image to the attribute I get the error: An unexpected error occurred. File does not exist.

Is there a way to check if an image exists, and if not, revert to a default image?
(C5.7)

Thanks in advance

Kurtopsy
 
hutman replied on at Permalink Reply
hutman
In your code you can add an if around the output of the image. It depends what kind of block you're using though how the code would look.
Kurtopsy replied on at Permalink Reply
Kurtopsy
Thanks for the reply hutman! I attempted an if statement around the output but kept getting error messages. It's going to be in a page list template. I'm confused on how to check if the attribute has an image or not. Do I check if it returns a 1 or 0?
hutman replied on at Permalink Best Answer Reply
hutman
If there is an image it will return an object, if there is not an image it will return a NULL so you can do something like

$file = $page->getAttribute('attribute_handle');
if($file){
//do things with this file object
}
Kurtopsy replied on at Permalink Reply
Kurtopsy
Perfect! Exactly what I needed. Thank you.