attribute - if statement php help..

Permalink 1 user found helpful
Hi chaps,

Quick bit of php help needed if possible.. I'm using the following code to pull the background image of a div from an attribute called background:

<div id="MyDivExample" style="background: url(<?php echo($c->getAttribute('background')->getVersion()->getRelativePath());?>) no-repeat bottom center">


All is working perfectly, but how could I add an 'if' statement so when there is no background image selected through the C5 properties it uses a default image that I can just link to within my theme/images folder. So I'm basically wanting it to say 'if background attribute is empty use images/myimage.jpeg'. Can any php guru's give me a hand?

Thanks for any help!

 
Mnkras replied on at Permalink Best Answer Reply
Mnkras
<?php
if($c->getAttribute('background')) {
 $code = $c->getAttribute('background')->getVersion()->getRelativePath();
} else {
 $code= '/path/to/img.png';
} ?>
<div id="MyDivExample" style="background: url(<?php echo($code);?>) no-repeat bottom center">
OliR replied on at Permalink Reply
Great stuff, worked a treat! Thanks for the help :-)