Adding an image attribute - C5 updates have flummoxed me

Permalink
It has been a while since I have built a site with C5 and things have kinda changed.

Let me first start by saying that I am a deisgner and not a developer... front-end I can do but the php stuff is pretty limited and I do a lot via trial and error.

Anyway all I want to do is add an if statement if the user does NOT add an image with the attribute but I keep getting an error back.

The code I in the top of the page type is:
<?php 
defined('C5_EXECUTE') or die("Access Denied.");
$this->inc('elements/header.php'); 
$large_picture_one = $c->getAttribute('body_shot_one')->getVersion()->getRelativePath();
$large_picture_two = $c->getAttribute('body_shot_two')->getVersion()->getRelativePath();
?>


in my main content I have:
<div class="model_pics">
<?php if($page->getAttribute('body_shot_one')): //is there an image? ?>         
<img src="<?php echo $large_picture_one ?>" width="229" style="margin-right:10px;"/>
<?php endif; ?>
<?php if($page->getAttribute('body_shot_two')): //is there an image? ?>
<img src="<?php echo $large_picture_two ?>" width="229" style="margin-right:5px;"/>
<?php endif; ?>
</div>


Do I need to add an image helper?

Any insight would be wicked

Thanks in advance for you patience...

dancer
 
ronyDdeveloper replied on at Permalink Reply
ronyDdeveloper
I'm not sure where the $page is coming from. Have you used the below code?
$page = Page::getCurrentPage();


Also are using $c to get page attribute. But I'd suggest to use $page instead of $c
$large_picture_one = $page->getAttribute('body_shot_one')->getVersion()->getRelativePath();
$large_picture_two = $page->getAttribute('body_shot_two')->getVersion()->getRelativePath();
dancer replied on at Permalink Reply
dancer
Thanks for your response ronyDdeveloper.

I put:

$page = Page::getCurrentPage();
$large_picture_one = $page->getAttribute('body_shot_one')->getVersion()->getRelativePath();
$large_picture_two = $page->getAttribute('body_shot_two')->getVersion()->getRelativePath();

at the top of the page but still the error:
"Fatal error: Call to a member function getAttribute() on a non-object in /Applications/MAMP/htdocs/concrete_models/themes/models/model.php on line 13"

and then pages that had both images stopped working too.

Full page code of interest here:
<?php 
defined('C5_EXECUTE') or die("Access Denied.");
$this->inc('elements/header.php'); 
$gender = $c->getAttribute('gender');
$height = $c->getAttribute('height');
$jean_size = $c->getAttribute('jean_size');
$dress_size = $c->getAttribute('dress_size');
$description = $c->getCollectionDescription();
$profile_picture = $c->getAttribute('profile_photo')->getVersion()->getRelativePath();
$large_picture_one = $c->getAttribute('body_shot_one')->getVersion()->getRelativePath();
$large_picture_two = $c->getAttribute('body_shot_two')->getVersion()->getRelativePath();
?>
         <h1 class="
            <?php $c->getCollectionName(); //displays the name of the current page
            $page = Page::getByID($c->getCollectionParentID());


thanks again
D!!