Jump to:

3459 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Central blocks of content that will display on other page types

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

Page: 1
Go to End
Author Topic: 1134 Views
  • Searly
    Avatar
    Community Member
    11 Posts

    Central blocks of content that will display on other page types Link to this post

    Hi there,

    I am trying to achieve following.
    I want to adjust the Homepage so i can add extra Links in an area of the Homepage (i.e landing page). So far no problem, as described in the tutorials, i can extend the Page.php and/or HomePage.php for extra textfields in the CMS.

    However i now want that the content that i have defined and created in the custom field on theHomepage (for example a group of links) will display in any other template that i define.

    Is this possible?

    Thanks

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Central blocks of content that will display on other page types Link to this post

    Hi Searly

    It is very easy to do stuff like this with SS, which is one of the reasons it's so great you are really not limited by any predefined ideas of how your content should be structured.

    So to answer your question, there are two obvious ways to do this that I can see. The first and probably simplest from where you are is to have a function in you Page.php controller which returns the homepage, therefore giving you access to any content stored in it. your function might look like this:

    public function GetHomePage(){
    return DataObject::get_one("HomePage");
    }

    then in any of your templates you can simple do this:

    <% control GetHomePage %>
    $Title
    $Content
    $SomeOtherFieldInHomePage
    <% end_control %>

    The other way to do this is to create a new page type for your common content, for example Footer.php or Sidebar.php which will store all the common fields you want to use. You can then fetch this page (once it has been created in the CMS) using the same type of function as above and use it's fields in the template.

    Hope that helps

  • Searly
    Avatar
    Community Member
    11 Posts

    Re: Central blocks of content that will display on other page types Link to this post

    Thanks for the quick response ...

    is it really that easy ... wow ...

    I am a silverstripe Newbie and the thing that attracted me mainly to it is the sane and intuitive user interface of the CMS. I am starting to play a bit more with it and building a site ...

    The more i do the more i love it, already i have been able to built what i want much faster than using Drupal.

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Central blocks of content that will display on other page types Link to this post

    from what I know of drupal/joomla there really is no comparison. If your willing to learn (or already know) a bit of php, then SS will be your best friend and the learning curve is so gradual that it's perfect for anyone who wants to go further. 3 months ago I barley knew PHP and only had a rough idea of what object orientation was (I'm still no expert of course!), since then SS has lead me through each step in such an ejoyable way that I havn't stopped and although there is still so much more to learn, at no point does it make you feel like you can't do something, rather that you just don't know how to do it yet!

    Of course it's still got a way to go before it becomes mainstream but I think it's gaining momentum.

    1134 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.