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:

Data Model Questions /

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

Show page list on homepage

Go to End

3 Posts   1817 Views


Community Member, 148 Posts

24 February 2009 at 10:43am

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.



Community Member, 607 Posts

24 February 2009 at 11:10am

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



Community Member, 148 Posts

24 February 2009 at 2:14pm

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


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