Image attributes... Basic help

Permalink
Hey there,

Sorry to keep posting but I have genuinely tried to hunt around for the right answer and I am none the wiser to date.

All I want to do is add some images to a page type that is pulled from the image attributes (3 in total). Sometimes not all images are added and this then throws back an error. I know I have to add an "if" statement but I am not sure of the syntax. I also know that I can call the image attribute at the top of the page type and then add it with the if statement within the <div>

I found this
<?php 
     $file = $page ->getAttribute ("body_shot_two");
     if(is_object($file)){
          $im = loader::helper('image');
          $im -> output($file);
    }
?>


But I then do not have any control of the
width="xx"


And I cannot add any custom CSS

Finally it also seems inefficient to add the above code for every attribute.. I know it is simple but I cannot find the correct solution anywhere...

dancer
 
dancer replied on at Permalink Reply
dancer
Ok, I cobbled some code together and this ended up working...
<?php
     if($c->getAttribute('body_shot_two')) {
    echo '<img src="' . $c->getAttribute('body_shot_two')->getVersion()->getRelativePath() .' "width="229" style="margin-right:5px;" />';
  }
?>


I know this is not the most efficient way of doing it and if anyone has a better way, please help :)

thanks