Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » I wanna make a sidebar, but how?

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

Page: 1 2 3 4 5
Go to End
Author Topic: 12365 Views
  • martin_w
    Avatar
    Community Member
    28 Posts

    Re: I wanna make a sidebar, but how? Link to this post

    I made that, but its still all white.

    by the way. I need to make "db/build?flush=1" right?
    But after db update its still all white.

    edit:
    must this code not look like this?

    function GetSidebar() {
       return DataObject::get_one("SidebarPage");
       }

    I mean "GetSidebar()" and not just "GetSidebar", without the braces?

  • martin_w
    Avatar
    Community Member
    28 Posts

    Re: I wanna make a sidebar, but how? Link to this post

    when I make "GetSidebar()" with braces, then works the page.. just the admin menu has a error..

    and now I get this error mail

    Error: Bad class to singleton() - SidebarPage
    At line 85 in *deleted*/Core.php

    user_error(Bad class to singleton() - SidebarPage,256)
    line 85 of Core.php

    singleton(SidebarPage)
    line 181 of CMSMain.php

    CMSMain->generateDataTreeHints()
    line 116 of CMSMain.php

    CMSMain->SiteTreeAsUL()
    call_user_func_array(Array,Array)
    line 404 of ViewableData.php

    ViewableData->XML_val(SiteTreeAsUL,,1)
    line 263 of .c*deleted*.CMSMain_left.ss

    include(*deleted*)
    line 197 of SSViewer.php

    SSViewer->process(CMSMain)
    line 763 of ViewableData.php

    ViewableData->renderWith(Array)
    line 365 of LeftAndMain.php

    LeftAndMain->Left()
    call_user_func_array(Array,Array)
    line 404 of ViewableData.php

    I deleted the server paths, dont want to write that here in the forum.

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: I wanna make a sidebar, but how? Link to this post

    ahh yea sorry, my bad!

    I think that bad singleton error is usually a typo as well, check all the class names for SidebarPage and just make sure everything matches up etc.

    if you cant find anything post your code and Ill take a look:)

  • martin_w
    Avatar
    Community Member
    28 Posts

    Re: I wanna make a sidebar, but how? Link to this post

    I found no more spelling mistakes

    in Page.php is this code

    function GetSidebar() {
       return DataObject::get_one("SidebarPage");
       }

    the code is in the class class Page_Controller extends ContentController {}

    then.. in my SideBarPage.php is this code

    <?php

    class SidebarPage extends Page {

       static $db = array(
       'SidebarText' => Text;
       );
       
       static $has_one = array(
       'Image1' => 'Image',
       'Image2' => 'Image',
       'Image3' => 'Image',
       );
       
       function getCMSFields() {
       $fields = parent::getCMSFields();
       
       $fields->addFieldToTab('Root.Content.Main', new TextAreaField('SidebarText'), 'Content');
       $fields->addFieldToTab("Root.Content.Images", new ImageField('Image1'),'Content');
       $fields->addFieldToTab("Root.Content.Images", new ImageField('Image2'),'Content');
       $fields->addFieldToTab("Root.Content.Images", new ImageField('Image3'),'Content');
       
       return $fields;
       }

    }

    class SidebarPage_Controller extends Page_Controller{

    }

    ?>

    and in themes/my_template/templates/Includes/SideBar.ss is

    <% control GetSidebar %>

    $SidebarText

    $Image1

    $Image2

    $Image3

    <% end_control %>

    and lastly in my Page.ss is
    <% include Sidebar %>

    I hope I forgot nothing.

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: I wanna make a sidebar, but how? Link to this post

    ok first I missed another 2 ' on this line:

    'SidebarText' => Text; should be 'Text';

    also you care calling <% include Sidebar %> but you .ss file is called SideBar, but seeing as its working in the template it's probably right in your actual code?

  • martin_w
    Avatar
    Community Member
    28 Posts

    Re: I wanna make a sidebar, but how? Link to this post

    edited all what you wrote, but its still not working, and since I edit "<% include Sidebar %>" to "<% include SideBar %>" is it again a white page.. But you are right, my .ss file is called SideBar and not Sidebar. So it must be right

    edit:
    <% control GetSidebar %> must maybe be <% control GetSidebar() %> ?

    but that dont works, too.

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: I wanna make a sidebar, but how? Link to this post

    hmm, I have tested your code and it seems to work ok for me :S must be something else.......not sure what though, let me think about it

  • martin_w
    Avatar
    Community Member
    28 Posts

    Re: I wanna make a sidebar, but how? Link to this post

    thats weird..

    in which page.ss do you have the "include"? in the templates/Page.ss or in templates/Layout/Page.ss ?
    but that probably doesnt matter.

    anways. thank you for your help again. I will look if I find some mistake what I've done.

    12365 Views
Page: 1 2 3 4 5
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.