481 Posts in 150 Topics by 238 members
| Go to End | Next > | |
| Author | Topic: | 4090 Views |
-
Making content on all pages editing on CMS

15 June 2009 at 9:02pm
Hi
I am searching solution for one problem I have.I have Silverstripe 2.3.1 version. I have website there I want to place various content on one page.
For example:
I have pages named "About us" and "Solution", these pages have main content area and sidebar area. I want that I could edit these pages on CMS: various content in main area; and the same content in sidebar area in all pages and sidebar area could be editing in CMS in one page and shown for public in all pages.I hope that I explained my problem well.
So how can I do this? Thanks for help. -
Re: Making content on all pages editing on CMS

16 June 2009 at 10:26pm
Yup that is a common request and easy to implement, have a look at this tutorial which will step you through it http://www.ssbits.com/create-a-static-sidebar/
-
Re: Making content on all pages editing on CMS

16 June 2009 at 11:05pm
Yeah, I do it like this:
1. I'll have a HomePage template, to which I add fields that I consider "global". (I will collect them under a "global" tab in the cms.)
2. On Page.php, I include the following function:
public function callHome(){
return DataObject::get_one('HomePage');
}3. This means that I can call home from every Page template (or a template based on a page type that extends from page) to show things that I've set in the "global" section on my home page in the cms. (For instance $callHome.WhateverField.)
-
Re: Making content on all pages editing on CMS

27 December 2009 at 2:18pm
SilverRay
Could you explain a little further what you are doing here?
I want to set my footer to be global. I want that a user can edit the footer info in an editer on a tab called "Footer" - like your "Global" tab.
Please help me with the steps I need to take to make this work.
Thank you,
Steve -
Re: Making content on all pages editing on CMS

27 December 2009 at 2:46pm Last edited: 27 December 2009 2:48pm
OK, well, I make use of the fact that your home page is always there and has a separate page type ("HomePage.php"). Example for HomePage.php:
<?php
class HomePage extends Page {
...
public static $db = array(
'SomeFooter' => 'Text'
);function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root', new TabSet('GlobalContent'));
$fields->addFieldToTab( 'Root.GlobalContent.Footer', new TextField('SomeFooter', 'Put Footer text here.'));
return $fields;
}
...
}class HomePage_Controller extends Page_Controller {
}?>
This means I declare a variable 'SomeFooter' to put in your Footer's content, and I create a tab for the editor in which you can actually do that. Then in Page.php:
class Page_Controller extends ContentController {
...
public function callHome(){
return DataObject::get_one('HomePage');
}
...
}?>
This means that in every page template of the type 'Page' (or a type extended thereof) I can call $callHome.SomeFooter to render the content of SomeFooter for that particular page. The function callHome calls the HomePage dataobject and -in this case- its SomeFooter attribute.
HTH
-
Re: Making content on all pages editing on CMS

27 December 2009 at 3:18pm Last edited: 27 December 2009 3:24pm
Thank you SilverRay!
You opened up a whole new world for me!
I will add to this post as I go along. The first thing I ran into was that I setup the $fields code after my other tab code - this removed all my tabs. So I pasted the $fields to the top, before the page tabs and they all came back.
I have added the editor ...
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root', new TabSet('GlobalContent'));
$fields->addFieldToTab( 'Root.GlobalContent.FooterContent', new HtmlEditorField('SomeFooter', 'Use the editer below to update your footer content'));To be continued...
The backend all seems fine. The values are saving and all if fine.
Onto the HomePage.ss file...
Should that just be a duplicate of the Page.ss file? I'm getting this error...
[Warning] file_get_contents() [function.file-get-contents]: Filename cannot be empty
GET /Line 277 in /home/landingp/public_html/sapphire/core/SSViewer.php
-
Re: Making content on all pages editing on CMS

27 December 2009 at 3:26pm
My Home Page (from HomePage.ss) is not showing up in the Behavior tab ??
Where is this function being called - callHome ?
public function callHome(){
return DataObject::get_one('HomePage');
} -
Re: Making content on all pages editing on CMS

27 December 2009 at 3:39pm
I can't seem to get my Home Page to show up - any ideas based on the error I'm getting?
| 4090 Views | ||
| Go to Top | Next > |


