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 /

Advice on making a banner template


Reply


4 Posts   1440 Views

Avatar
D&B

Community Member, 4 Posts

27 November 2009 at 7:16am

Here is what I'm after:

My site's homepage uses JQuery to cycle through a set of banners. Each banner has a title, text, image and a link to another page within the site.

I've found two ways of doing this. The first is to add all the fields to the homepage, e.g. make a tab called Banner 1 with the four necessary fields, and repeat (Banner 2, 3, etc.). But, if I do it this way I'm limited to a set number of banners (and HomePage.php gets too messy for my liking).

What I really need is the ability to add as many banners as I want. My second approach allows this but I'm not sure if it is considered correct. Basically I've created a banner holder and a banner page. Both page types have a redirect to stop them from being visited directly:

   public function init() {
      parent::init();
      Director::redirect(Director::baseURL());
   }

I then use a control, e.g. <% control FeatureBanners %> to display them on the homepage.

Is this the best way to achieve what I'm after? Any suggestions or a better solution would be greatly appreciated.

I also couldn't get redirectPerm to work, which I'm guessing is better than redirect in this case.

Thanks.

Avatar
Double-A-Ron

Community Member, 604 Posts

27 November 2009 at 8:57am

If it were me, I'd create a Banners dataobject and create a "has_many" relationship on HomePage.

Then, use dataobjectmanager to maintain your banners on one tab on your home page. http://doc.silverstripe.org/doku.php?id=modules:dataobjectmanager

You will be able to add as many as you want, and also manage any extra fields a banner may have, such as URL link.

Then, you can use a "FetchBanner" method on your HomePage controller that returns a random banner, or all of them, however you want.

Aaron.

Avatar
Taffy

Community Member, 119 Posts

28 November 2009 at 1:01am

Edited: 28/11/2009 1:02am

There is some banner stuff on http://ssbits.com/working-with-banners/

Not sure if it'll help though.

Avatar
D&B

Community Member, 4 Posts

29 November 2009 at 11:08am

Thank you!