Jump to:

3393 Posts in 976 Topics by 852 members

Template Questions

SilverStripe Forums » Template Questions » Solved: Creating a banner tool for a site?

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

Page: 1
Go to End
Author Topic: 1589 Views
  • jailja
    Avatar
    Community Member
    7 Posts

    Solved: Creating a banner tool for a site? Link to this post

    Greetings again. I am trying to create a banner tool in a site using SS, but I am not sure how that could be done. Anyone willing to help?

    Banner is on the top side of the page, and I have the template included in Page.ss like this: <% include BannersTop %> (and BannersTop.ss in /themes/mysite/templates/includes/). Other banner spot is on the sidebar (but thats not important, nor the problem).

    Now, I would want to be able to disable/activate 1 or more banners sidewide from one page. I think it should be done by making an BannerHolder -page, which contains single banners as sub pages. Then these banners would have a tick box in admin view for showing/not showing on a pagewide.

    Is this possible?

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: Solved: Creating a banner tool for a site? Link to this post

    rather than page types i suggest you to have dataobjects. and create relationships over Pages, and the DataObjects, using the has_one / has_many arrays.

    You can use ComplexTableField to create relationships. Have a look at the Diary module which I maintain and see whether you can understand the code.

  • jailja
    Avatar
    Community Member
    7 Posts

    Re: Solved: Creating a banner tool for a site? Link to this post

    Thanks, I'll check the Diary module.

  • jailja
    Avatar
    Community Member
    7 Posts

    Re: Solved: Creating a banner tool for a site? Link to this post

    Diary was too hard for me to understand. >.<

    Oh well, I did manage to solve this on other way.

    Page.php:

    <?php
    class Page extends SiteTree {
       static $db = array(
          'Aktiivinen' => 'Boolean'    
       );
       static $has_one = array(
       "Banner" => "Banner",   
       );   
    }

    class Page_Controller extends ContentController {   
       public function init() {
          parent::init();
       }   
       
       function topBanners() {
          $bansku = DataObject::get("BannerPage");   
          return $bansku;
       }
    }
    ?>

    HomePage.ss:

    <% control topBanners %>
    <% if Aktiivinen %>
    <div id="topBanner"><a href="$Url">$Bannerikuva</a></div>
    <% end_if %>
    <% end_control %>

    BannerPage.php:

    <?php
    /**
    * Defines the BannerPage page type
    */
    class BannerPage extends Page {
       static $db = array(
          'Url' => 'Text',   
       );
       static $has_one = array(
          'Bannerikuva' => 'Image',
       );
       static $icon = "themes/tutorial/images/treeicons/banners";

       function getCMSFields() {
          $fields = parent::getCMSFields();
          $fields->addFieldToTab('Root.Content.Main', new CheckboxField ('Aktiivinen'));
          $fields->addFieldToTab('Root.Content.Main', new TextField('Url'));      
          $fields->addFieldToTab("Root.Content.Main", new ImageField('Bannerikuva'));
          $fields->removeFieldFromTab("Root.Content.Main","Content");            
          $fields->removeFieldFromTab("Root.Content.Main","Navigation label");      
          return $fields;
       }
    }

    class BannerPage_Controller extends Page_Controller {
    }

    ?>

    Dunno if its the right way to do it, but it definetly works.

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: Solved: Creating a banner tool for a site? Link to this post

    Rather than a new Page type I would use DataObjects, a Page is a lower level in the hierarchy, which means that it inherits from the DataObject.

    Anyway the fact I go for DataObjects is that it does not influence the SiteTree, as the banners wont be used for any other purpose than storing an image.

    Read these

    http://doc.silverstripe.org/doku.php?id=dataobject
    http://doc.silverstripe.org/doku.php?id=recipes:many_many-example

    1589 Views
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.