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

Page independent Content (global Content)


Reply

6 Posts   6944 Views

Avatar
loeppel

13 July 2009 at 2:33am Community Member, 7 Posts

Hi folks,
i know someting about the programming model of silverstripe, but one thing is hard to find out (even with the german book SilverStripe). How can i have some page independet content on each page. This content should be editable in the backend.

Any suggestions?

Avatar
banal

13 July 2009 at 4:17am Community Member, 901 Posts

Hi

Usually I add "global" content like this to a Page that only exists once. Like the HomePage.
Then I add a getter Method to the Page baseclass to always have access to the HomePage. Eg:

// this belongs in Page_Controller
public function HomePage(){
   return DataObject::get_one('HomePage');
}

So, if my HomePage has a Field called "GlobalContent", I can output it in any template using:
$HomePage.GlobalContent

Avatar
loeppel

16 July 2009 at 1:04am Community Member, 7 Posts

Thank you very much!
This works great!
I think SilverStripe should provide such a thing for some global template variables, such as Page Title, Site Name and Tagline (etc.)

Greets,
loeppel

Avatar
me.yay

21 February 2010 at 12:24am (Last edited: 21 February 2010 12:40am), Community Member, 14 Posts

Hi,

seems like HomePage is a sublcass of Page. And the function returns the first page having the pagetype HomePage.

Is it possible to use the template var $HomePage.GlobalContent inside the content of another page using tinyMCE?

I am just currious because UserDefinedForms is uses $UserDefinedForms inside content which refers to the same function in the contoller.

Does this work for $HomePage.Content aswell inside $Content of the current page (via tinyMCE)?

kind regards
Metin

Avatar
Willr

22 February 2010 at 6:06pm Forum Moderator, 5511 Posts

Is it possible to use the template var $HomePage.GlobalContent inside the content of another page using tinyMCE?

I am just currious because UserDefinedForms is uses $UserDefinedForms inside content which refers to the same function in the contoller.

UserForms uses a method like http://doc.silverstripe.org/doku.php?id=recipes:customising-content-in-your-templates to get that to work which is a bit nasty but the easiest solution for now.

Avatar
me.yay

26 February 2010 at 2:50am Community Member, 14 Posts

Thanks Willr, this looks exactly like what i was looking for :)