Jump to:

5539 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Page independent Content (global Content)

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 6898 Views
  • loeppel
    Avatar
    Community Member
    7 Posts

    Page independent Content (global Content) Link to this post

    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?

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Page independent Content (global Content) Link to this post

    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

  • loeppel
    Avatar
    Community Member
    7 Posts

    Re: Page independent Content (global Content) Link to this post

    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

  • me.yay
    Avatar
    Community Member
    14 Posts

    Re: Page independent Content (global Content) Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: Page independent Content (global Content) Link to this post

    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.

  • me.yay
    Avatar
    Community Member
    14 Posts

    Re: Page independent Content (global Content) Link to this post

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

    6898 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.