Custom Attributes (PHP) Help

Permalink
If I add a custom attribute like main_image, using the following code on the page.

<img src="<?php echo ($c->getAttribute('main_image')->getVersion()->getRelativePath());?>" class="img-responsive center-block">

how do I write the php code to use a fallback image if they haven't added one, as if I create the page and I don't add an image I get a error of call to none object.

Cheers

Mal

 
ronyDdeveloper replied on at Permalink Best Answer Reply
ronyDdeveloper
<?php 
if($c->getAttribute('main_image')){
  $src = $c->getAttribute('main_image')->getVersion()->getRelativePath();
}
else {
  $src = 'Your not found image path';
}
?>
<img src="<?php echo $src?>" class="img-responsive center-block">