5098 Posts in 1518 Topics by 1115 members
| Go to End | Next > | |
| Author | Topic: | 10978 Views |
-
Re: I wanna make a sidebar, but how?

12 January 2009 at 2:19am Last edited: 12 January 2009 2:21am
which versoin are you using, I am using 2.23.......not sure if this would work with 2.3, it should but I havn't got round to testing much on that version.
here is my code:
SidebarPage.php
<?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{
}
?>
Page.php:<?php
class Page extends SiteTree {
static $db = array(
);
}class Page_Controller extends ContentController {
function GetSidebar() {
return DataObject::get_one("SidebarPage");
}
}?>
Sidebar.ss
<% control GetSidebar %>
$SidebarText
$Image1
$Image2
$Image3
<% end_control %>
Page.ss<% include Sidebar %>
-
Re: I wanna make a sidebar, but how?

12 January 2009 at 3:16am Last edited: 12 January 2009 3:18am
I use 2.2.3, the newest.
When I delete the SidebarPage.php, then works my admin. So I think the error must be in this file.
Must the function not be in class SidebarPage_Controller extends Page_Controller{}?
I think so, it works when I put the function in it.
(but first after db flush) -
Re: I wanna make a sidebar, but how?

12 January 2009 at 3:28am
now I got it really work..
I was wrong with "Must the function not be in class SidebarPage_Controller extends Page_Controller{}? "I think I had problems with db flush, thats why it worked not earlier.
very big thank you.
-
Re: I wanna make a sidebar, but how?

12 January 2009 at 4:59am Last edited: 12 January 2009 5:01am
great to hear you got it working, the GetSidebar() function must go into Page.php beacause you want it to be available on every page. If we put it into SidebarPage.php then it would only be available when we were on a SidebarPage, which in this case we would never be as we are not using that page on its own.
Anyway we got there in the end and your very welcome
-
Re: I wanna make a sidebar, but how?

12 January 2009 at 5:22am
and your very welcome
I think then I may ask one more question ;)
is it possible that in the text fields is also html available?
-
Re: I wanna make a sidebar, but how?

12 January 2009 at 6:36am Last edited: 12 January 2009 6:38am
You sure can
You just have to use the HtmlEditorField field type. To do that add this to your SidebarPage class:
static $db = array(
'FieldName' => 'HTMLText'
)function getCMSFields($cms) {
$fields = parent::getCMSFields($cms);$fields->addFieldToTab("Root.Content.Images", new HtmlEditorField( "FieldName", "HTML Editor"));
return $fields;
}that will add a tinyMCE editor like the one for Content
There is a list of all the form field types you can use here: http://doc.silverstripe.com/doku.php?id=form-field-types
-
Re: I wanna make a sidebar, but how?

7 March 2009 at 9:36pm
I have followed this and everything seems to work until I load up the sidebar.php file, i then try to flush the DB and it comes up with a silverstripe website error and i cant flush or go into the admin area
Remove that one file and it works.
Im using silverstripe 2.3.0
The page i get up is a standard web error page so i cant see where it has the problem and not sure what in sidebar.php would have the problem
| 10978 Views | ||
| Go to Top | Next > |


