Jump to:

3461 Posts in 1065 Topics by 740 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Banner Image defaults to parent

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1358 Views
  • NickJacobs
    Community Member
    144 Posts

    Banner Image defaults to parent Link to this post

    In a site I'm building I want different banner images for each section of the site, and so want a page to default it's parents banner if one is not set. I have set up the following code, but I don't see anything on the page

    the code is based on this archived post

    In Page.php

    class Page extends SiteTree {
       static $has_one = array(
       'BannerImage' => 'Image'

    class Page_Controller extends ContentController {
    function getBannerImage() {

    $BannerImage = $this->getParentBannerImage($this);
    return $BannerImage;

    private function getParentBannerImage($CurrentPage){
    $Parent = $CurrentPage->Parent;


    return $BannerImage;
    // We found the current header! Let's return it!
    } else {
    return $this->getParentBannerImage($Parent);
    // We didn't find a header,so we have to call ourselves again

    } else {
    return false;

    In Page.ss i'll just do something like this:

    <div id="banner" style="background:url(<% control getBannerImage %>$URL<% end_control %>)"></div>

    So, it's probably something completely obvious...just not to me at the mo!

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.