Jump to:

23355 Posts in 17838 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Looking to display content from two different page types in one page holder

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

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

Page: 1
Go to End
Author Topic: 1194 Views
  • evilish
    Avatar
    Community Member
    9 Posts

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

    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

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Looking to display content from two different page types in one page holder Link to this post

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

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