Image/File Attribute returning error when blank

Permalink 1 user found helpful
Hi Guys,

I'm using the Image/File Attribute and if no image is selected it will return the following error

--------------
Fatal error: Call to a member function getVersion() on a non-object in /home/content/w/a/l/walkatjurraorg/html/themes/walkatjurra/elements/header.php on line 26
---------------
And this is what's on line 26

<img src="<?php echo($c->getAttribute('page_bg')->getVersion()->getRelativePath());?>" />

Basically, it seems that if the field/attribute is not populated it will return the error because on another page where an image was loaded it works fine.

My question, is it possible to have it both populate or not, and what would the code be like.

Thanks & Regards
Said

View Replies: View Best Answer
Said replied on at Permalink Best Answer Reply
Manage to figure it out and if anyone is interested this is how I did it

<?php    
      if($c->getAttribute('page_bg')){
       echo '<img src="'.$c->getAttribute('page_bg')->getVersion()->getRelativePath().'" alt="" />';
      }
   echo ""
   ?>
juddc replied on at Permalink Reply
juddc
Thank you - just what I was looking for.