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.

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

Avatar
evilish

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

Avatar
bummzack

Community Member, 904 Posts

9 July 2010 at 7:09pm

Hi.

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