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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

Central blocks of content that will display on other page types


Go to End


4 Posts   2324 Views

Avatar
Searly

Community Member, 11 Posts

12 February 2009 at 4:23am

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

Avatar
Carbon Crayon

Community Member, 598 Posts

12 February 2009 at 7:04am

Edited: 12/02/2009 7:09am

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 :)

Avatar
Searly

Community Member, 11 Posts

12 February 2009 at 7:56am

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.

Avatar
Carbon Crayon

Community Member, 598 Posts

12 February 2009 at 10:30am

Edited: 12/02/2009 10:36am

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.