Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions /

Solved: Creating a banner tool for a site?


Reply


5 Posts   1682 Views

Avatar
jailja

Community Member, 7 Posts

10 November 2009 at 2:20am

Edited: 10/11/2009 12:17pm

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?

Avatar
Nivanka

Community Member, 397 Posts

10 November 2009 at 3:47am

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.

Avatar
jailja

Community Member, 7 Posts

10 November 2009 at 5:06am

Thanks, I'll check the Diary module.

Avatar
jailja

Community Member, 7 Posts

10 November 2009 at 11:04am

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. :)

Avatar
Nivanka

Community Member, 397 Posts

10 November 2009 at 2:52pm

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

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