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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Looking to display content from two different page types in one page holder

Go to End

2 Posts   1589 Views


Community Member, 9 Posts

9 July 2010 at 6:24pm

Hey everyone,

Currently using SilverStripe to create a little neat and tidy website for a client. Implementing the design into SilverStripe went really well and to be honest, I'am actually really suprised at how quickly I was able to implement the typical editable areas and an imagegallery.

The only thing I'am struggling with at the moment is displaying content from two different page types in one page holder.

For example,

I have a "Homepage Holder" with three CMS editable content areas. The first paragraph of the "About Us" page with a read more link, a list of the most recent testimonials (5) and some contact details.

The structure looks something like this:

-[ Homepage (Holder displaying "About Us" excert and latest testimonials)
--[ About Us
--[ Testimonials (Holder displaying all testimonials)
----[ Bob Smiths Testimonial
----[ John Blacks Testimonial

(Sorry about the crap diagram)

Now, I have tried a bending the news tutorial to my needs but I must be missing something because when it comes to displaying the contents of say the "About Us" page on the "Homepage Holder" I get nothing.

Can any of you guys think of any tutorials or similar examples out there of what I'am trying to accomplish here? Or am I going about it in a totally unconventional way and should try something a little different?

Any help much appreciated,
- Evilish


Community Member, 904 Posts

9 July 2010 at 7:09pm


Displaying the Testimonials on the "Testimonial Holder" Page should be as easy as using <% control Children %> in the Holder-Template.
To get Testimonials and About-Us on the Homepage, I suggest you do the following:

Extend the Homepage class like this:

public static $has_one = array(
	'AboutUsPage' => 'SiteTree'

In the getCMSFields method, add the following:

$fields->addFieldToTab('Root.Content.Main', new TreeDropdownField('AboutUsPageID', 'About Us Page', 'SiteTree'));

After your run dev/build and entering the cms, you should have a new Drowdown on your Homepage where you can select the "About Us Page".
In the template of the HomePage you can then access the contents of the selected page by writing:

<% if AboutUsPage %>
<% control AboutUsPage %>
... your markup here.. eg. $Content.FirstParagraph
<% end_control %>
<% end_if %>

With that approach, the About Us Page does not even have to be a child of the HomePage.
To list the most recent Testimonials, write a function like this in your Homepage class (assuming, that Testimonial is also a custom Page class):

public function TestimonialList($limit){
	return DataObject::get('Testimonial', '', 'Created DESC', '', (int)$limit);

In your template you can then use:

<% control TestimonialList(5) %>
.. access testimonial data here.. eg. <a href="$Link">$Title</a>
<% end_control %>

To output a list of most recent testimonials (in this example 5).