Images not display from page attributes

Permalink
Hello

I've created my theme as I require with a page called break_page I've assigned the following Page/Theme Attributes:

is_featured
page_list_thumbnail
main_image
external_site_url

When cretating a new page using the break_page.php I have managed to find an add onhttp://www.concrete5.org/marketplace/addons/page-properties/... to add page title & page description to the page when I fill in all the page properties.

I have managed to get external_url displaying by the following:
<?php echo $c->getAttribute('external_site_url'); ?>

But doing the same for Images I get errors, after a quick look online, I found the following code:

$file = $page->getAttribute("main_image");
if (is_object($file)) {
    $im = Loader::helper('image');
    $im->output($file);


but I now get an error:

Fatal error: Call to a member function getAttribute() on a non-object in D:\_sites\c5test\themes\mytheme\break_page on line 44

unsure why???

Could someone let me know how to pull the image on to the page when creating the page, in the same way I can add page title, description & external_site_url

I've placed below the break_page theme template code as it won't let me attached the page?? to see if I'm doing this right.
<!DOCTYPE html>
<html>
<head>
<?php
  $u = new User();
  if($u->isRegistered()) {
      Loader::element('header_required');
  }
  else {
   $page = Page::getCurrentPage();
   echo '<title>'.$page->getCollectionName().'</title>';
  }
?>
<link href="<?php echo $this->getThemePath(); ?>/css/bootstrap.min.css" rel="stylesheet">
<link href="<?php echo $this->getThemePath(); ?>/css/font-awesome.css" rel="stylesheet">


Any help appreciated.

Cheers

Mal

 
andrewjaff replied on at Permalink Best Answer Reply
andrewjaff
Hi,

Please use like this
<img src="<?php echo ($c->getAttribute('attribute_handle')->getVersion()->getRelativePath());?>" width="120px" height="160px">


Thanks
Andrew
osgmal replied on at Permalink Reply
Thanks Andrew

Much appreciated I've been going nowhere fast for last 2 days.

Cheers

Mal