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   7090 Views

Avatar
loeppel

Community Member, 7 Posts

13 July 2009 at 2:33am

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

Community Member, 901 Posts

13 July 2009 at 4:17am

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

Community Member, 7 Posts

16 July 2009 at 1:04am

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

Community Member, 14 Posts

21 February 2010 at 12:24am

Edited: 21/02/2010 12:40am

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

Forum Moderator, 5513 Posts

22 February 2010 at 6:06pm

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

Community Member, 14 Posts

26 February 2010 at 2:50am

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