Jump to:

22977 Posts in 11806 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » How to fill my sidebar?

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 885 Views
  • suntrop
    Avatar
    Community Member
    131 Posts

    How to fill my sidebar? Link to this post

    On my website is a sidebar where I want to show some related informations, related pages, internal promotions etc.

    At first I thought I'll create a new tab and some text-inputs in the back-end to write all these (it's a pretty cool feature in SS . But as I've seen there are about 15-20 "snippets" I want to use and they repeat on other pages I think it isn't the best way to write the same more than once.

    Is there a nice and cool way in SS I can fill my sidebar? Can you please give me some insights and share experience? That would be great!

  • ampedup
    Avatar
    Community Member
    133 Posts

    Re: How to fill my sidebar? Link to this post

    From what I understand, you want one unique sidebar that you can edit in the cms and display on multiple pages?

    What I would do is create a new page in the root of the website called 'Sidebar'.
    Make this page hidden from the menu and search.
    In the content put what you want in the sidebar.
    Then in the page templates, where you want the side bar to go you call the following:

    <% control Page(sidebar) %>
    $Content
    <% end_control %>

  • suntrop
    Avatar
    Community Member
    131 Posts

    Re: How to fill my sidebar? Link to this post

    Hi ampedup.
    Yes, I want a unique sidebar but not only one but for different sections different sidebars (content).

    I followed an example (German SS Forum http://www.silverstripes.de/mvc-coding/show/130?showPost=1434) but can not complete it.

    What I have:
    There is a new SiteTree select field above my 'content' in the back-end where I can select a page. But when I click save my selection gets lost, it seems SS can't save it in the DB, although there is no error.

    The Code: (mysite/code/Page.php)

    class Page extends SiteTree {
       
       static $db = array(
       );
       static $has_one = array(
          'Hintergrundbild' => 'Image',
          'Sidebar' => 'Page'
       );

    // Verbindung Hintergrundbild zur Bild-Datenbank
    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab("Root.Content.Hintergrundbild", new ImageField('Hintergrundbild'));
    $fields->addFieldToTab('Root.Content.Main', new TreeDropdownField("Sidebar", "Sidebar anzeigen", "SiteTree"), 'Content');
       
    return $fields;
    }
       
    }

    Code 2: (mysite/code/Sidebar.php)

    <?php

    class Sidebar extends Page {
    static $db = array();
    static $has_one = array();
    }

    class Sidebar_Controller extends Page_Controller {

    }

    ?>

    Code 3: (themes/n1/templates/Page.ss)

    <p>Start Sidebar</p>
                <% control Sidebar %>
                 <div id="contentright">
                 sidebar Content: $Content
                 </div>
                <% end_control %>

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