I'm having trouble outputting a $has_one banner image ($banner), and looping some data objects setup via $has_many ($Sections). I've implemented these before, and just can't work out what I'm doing wrong! Both the image and the data objects have been added and are appearing as intended in the CMS, and are associated with the correct page. I've rerun /dev/build/ and ?flush. Here's my template code for templates/Layout/ServicePage.ss:
<% if $Banner %>
<header class="page-banner">
<figure class="media">
<% with $Banner.SetWidth(1920) %>
<img src="$URL" alt="" title="" width="$Width" height="$Height">
<% end_with %>
</figure>
</header>
<% end_if %>
<div class="article-content has-sidebar">
<div class="wrapper">
<article class="unit article-body nudge-up">
<nav class="bread">
<ul>
<li><a href="$BaseHref" title="$SiteConfig.Title">Home</a> / </li>
<% with $Level(2) %>
<li><a href="$Link" title="$Title">$MenuTitle</a> / </li>
<% end_with %>
<li class="long">$Title</li>
</ul>
</nav>
<h1 class="heading2">
<i class="left has-circle">
<svg class="icon-bank">
<use xlink:href="$ThemeDir/images/icons/icons.svg#icon-bank"></use>
</svg>
</i>
<span>$Title</span>
</h1>
<h2 class="heading3">$Intro</h2>
<div class="editor-content">
$Content
</div>
<% loop $Sections %>
<section class="section">
<div class="column">
<i class="has-circle">
<svg class="icon-help">
<use xlink:href="$ThemeDir/images/icons/icons.svg#icon-help"></use>
</svg>
</i>
</div>
<div class="column">
<h3 class="heading5">$Title</h3>
<div class="editor-content">
$Content
</div>
</div>
</section>
<% end_loop %>
</article>
<aside class="unit article-sidebar nudge-up">
WIDGETS HEREE
</aside>
</div>
</div>
Here's mysite/code/ServicePage.php class:
class ServicePage extends Page {
private static $db = array (
'Intro' => 'Text',
'USPStripIntro' => 'Varchar(255)'
);
private static $has_one = array (
'Banner' => 'Image'
);
private static $has_many = array (
'Sections' => 'ServiceSection'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Main', TextareaField::create('Intro','The introduction for the page'),'Content');
$fields->addFieldToTab('Root.Main', TextField::create('USPStripIntro','USP Intro Text'),'Content');
$fields->addFieldToTab('Root.Attachments', $banner = UploadField::create(
'Banner',
'The banner image for the page'
));
$fields->addFieldToTab('Root.Sections', GridField::create(
'Sections',
'Sections for this page',
$this->Sections(),
GridFieldConfig_RecordEditor::create()
));
$banner
->setFolderName('page-banners')
->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png'));
return $fields;
}
}
class Service_Controller extends Page_Controller {
}
Am I missing something?