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
Is there a way to check if an image exists, and if not, revert to a default image?
(C5.7)
Thanks in advance
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.
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?
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 }
Perfect! Exactly what I needed. Thank you.