Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Show page list on homepage

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

Page: 1
Go to End
Author Topic: 1186 Views
  • NickJacobs
    Community Member
    144 Posts

    Show page list on homepage Link to this post

    Hi, I want to be able to have a "teaser" list of other pages (with short description) displayed on the homepage of a site. I have created a "Show on Homepage" checkbox (in Page.php) but not really sure how to build the function to be able to access this for the homepage. Any help will be appreciated.


  • Double-A-Ron
    Community Member
    604 Posts

    Re: Show page list on homepage Link to this post

    Hi mate,

    Surely this isn't much different from how your navigation is built.

    I do something similar, but it's a featured page (a tour). Only one, but I have access to everything to do with that page - teaser, images etc.

    Maybe you can adapt this:


    class HomePage_Controller extends Page_Controller {

       // Get featured tour data
       function getFeaturedTour() {
          //return DataObject::get_one('Tour');
          return DataObject::get_one('Tour', 'TourLengthDays>0', false, 'RAND()');

    Where 'Tour' is the type of page. You probably want to use get instead of get_one, but I can't find it in the docs.


    <% control getFeaturedTour %>
    <div class="featured">
    <div class="featured-top">
    <div class="featured-btm">
    <h4>Featured Tour</h4>
    <a href="$Link">
    <h5 style="margin: 0px">
    <a href="$Link" style="color:#023107">$Title</a>
    <small>$TourLeavesFrom to $TourEndsAt - $TourLengthDays Days</small>
    <% if TourTeaser %>
    <div style="font-weight: normal; text-align: justify; margin-right: 5px">$TourTeaser</div>
    <p><a href="$Link">Click for details</a></p>
    <% end_if %>
    <% end_control %>

    As you can see, I have access to all fields in the Page type.

    Maybe a start. There may be an easier way with 2.3. The above is for 2.2.3


  • NickJacobs
    Community Member
    144 Posts

    Re: Show page list on homepage Link to this post

    Great...yeah I thought about it a bit more and came up with this:

    in HomePage.php

    function getHomePods(){
             return DataObject::get("Page","ShowInMenus = 1 AND ShowOnHomePage = 1", "", "",20);

    in HomePage.ss

    <% control getHomePods %>
          <div class="pagepod">
          <div class="pagepodtext"><h2>$Title</h2>
          <p>$Content.LimitWordCountPlainText(25)<a href="$Link" class="moreinfo">more info</a></p>
          <div class="pagepodimg">$TeaserImage.SetWidth(175)</div>
          <div class="clearer"></div>

       <% end_control %>

    I'll develop it as I go, but that works great for now. CHeers.

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.