Jump to:

3435 Posts in 1026 Topics by 866 members

Template Questions

SilverStripe Forums » Template Questions » Advice on making a banner template

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

Page: 1
Go to End
Author Topic: 1330 Views
  • D&B
    Avatar
    Community Member
    4 Posts

    Advice on making a banner template Link to this post

    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.

  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Re: Advice on making a banner template Link to this post

    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.

  • Taffy
    Avatar
    Community Member
    119 Posts

    Re: Advice on making a banner template Link to this post

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

    Not sure if it'll help though.

  • D&B
    Avatar
    Community Member
    4 Posts

    Re: Advice on making a banner template Link to this post

    Thank you!

    1330 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.