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.

Customising the CMS /

I wanna make a sidebar, but how?


Reply


37 Posts   13350 Views

Avatar
martin_w

Community Member, 28 Posts

12 January 2009 at 12:57am

Edited: 12/01/2009 1:09am

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?

Avatar
martin_w

Community Member, 28 Posts

12 January 2009 at 1:14am

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.

Avatar
Carbon Crayon

Community Member, 598 Posts

12 January 2009 at 1:27am

Edited: 12/01/2009 1:27am

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

Avatar
martin_w

Community Member, 28 Posts

12 January 2009 at 1:44am

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.

Avatar
Carbon Crayon

Community Member, 598 Posts

12 January 2009 at 1:57am

Edited: 12/01/2009 2:00am

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?

Avatar
martin_w

Community Member, 28 Posts

12 January 2009 at 2:04am

Edited: 12/01/2009 2:05am

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.

Avatar
Carbon Crayon

Community Member, 598 Posts

12 January 2009 at 2:09am

Edited: 12/01/2009 2:11am

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

Avatar
martin_w

Community Member, 28 Posts

12 January 2009 at 2:14am

Edited: 12/01/2009 2:15am

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.