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

LatestNews not shown in HomePage

Go to End

5 Posts   1461 Views


Community Member, 7 Posts

15 October 2009 at 2:39am


I am new to SS and I have a problem. I made the tutorial 2 using the code posted online, modifying both
my HomePage.php and my from the Layout folder in themes, but nothing happens. The news
do not get displayed on my HomePage no matter how I change the code. I use my own theme, and not a
SS pre-built theme. I post the code here:

HomePage.php ***from mysite/code***

function LatestNewsItems($num=5) {
$news = DataObject::get_one("ArticleHolder");
return ($news) ? DataObject::get("ArticlePage", "ParentID = '$news->ID'", "Date DESC", "", $num) : false;
} ***from themes/mytheme/templates/Layout***

<div id="Header">
<div id="Navigation">
<% include Navigation %>
<div id="Banner"></div>

<div id="News">
<div id="NewsList">
<% control LatestNewsItems %>
<li class="newsDateTitle"><a href="$Link" title="Read more on &quot;{$Title}&quot;">$Title</a></li>
<li class="newsDateTitle">$Date.Nice</li>
<li class="newsSummary">$Content.FirstParagraph<a href="$Link" title="Read more on &quot;{$Title}&quot;">Read more &gt;&gt;</a></li>
<% end_control %>
<div id="Newsletter"> </div>
<div id="Content" class="typography">
<div id="Layout1">
<div id="Footer"></div>

I tried flushing the page many times but nothing happens. Please help me out!
Have a nice day!


Forum Moderator, 5523 Posts

15 October 2009 at 1:51pm

Check the homepage is of type 'HomePage' in the CMS - Under the behaviour tab on the page you should see what class type it is. Make sure its set to the home one.

Next thing to check is that LatestNewsItems is in the HomePage_Controller class in HomePage. You could also try and move the LatestNewsItems function to the Page_Controller class in Page.php and try it there


Community Member, 7 Posts

15 October 2009 at 7:45pm

You were right. I misplaced the function under the final '}' of the function HomePage_Controller extends Page_Controller.
The Home page is of HomePage type. Now the code looks like this:



class HomePage extends Page {

public static $db = array(

public static $has_one = array(


class HomePage_Controller extends Page_Controller {

public function init() {

// Note: you should use SS template require tags inside your templates
// instead of putting Requirements calls here. However these are
// included so that our older themes still work

* Site search form
function SearchForm() {
$searchText = isset($_REQUEST['Search']) ? $_REQUEST['Search'] : 'Search';
$fields = new FieldSet(
new TextField("Search", "", $searchText)
$actions = new FieldSet(
new FormAction('results', 'Search')

return new SearchForm($this, "SearchForm", $fields, $actions);

* Process and render search results
function results($data, $form){
$data = array(
'Results' => $form->getResults(),
'Query' => $form->getSearchQuery(),
'Title' => 'Search Results'

return $this->customise($data)->renderWith(array('Page_results', 'Page'));

function LatestNewsItems($num=5) {
$newssection = DataObject::get_one("News");
return ($newssection) ? DataObject::get("Article01", "ParentID = '$news->ID'", "Date DESC", "", $num) : false;



I get an error though:

[User Error] Bad class to singleton() - News
GET /silverstripe/?flush=1

Line 261 in C:\wamp\www\silverstripe\sapphire\core\Core.php

252 *
253 * @param string $className
254 * @return Object
255 */
256 function singleton($className) {
257 global $_SINGLETONS;
258 if(!isset($className)) user_error("singleton() Called without a class", E_USER_ERROR);
259 if(!is_string($className)) user_error("singleton() passed bad class_name: " . var_export($className,true), E_USER_ERROR);
260 if(!isset($_SINGLETONS[$className])) {
261 if(!class_exists($className)) user_error("Bad class to singleton() - $className", E_USER_ERROR);
262 $_SINGLETONS[$className] = Object::strong_create($className,null, true);
263 if(!$_SINGLETONS[$className]) user_error("singleton() Unknown class '$className'", E_USER_ERROR);
264 }
265 return $_SINGLETONS[$className];
266 }


* Bad class to singleton() - News
Line 261 of Core.php
* singleton(News)
Line 2464 of DataObject.php
* DataObject::get_one(News)
Line 56 of HomePage.php
* HomePage_Controller->LatestNewsItems()
* call_user_func_array(Array,Array)
Line 318 of ViewableData.php
* ViewableData->obj(LatestNewsItems)
Line 50 of
* include(C:\Windows\Temp\silverstripe-cacheC--wamp-www-silverstripe\
Line 354 of SSViewer.php
* SSViewer->process(HomePage_Controller)
Line 346 of SSViewer.php
* SSViewer->process(HomePage_Controller)
Line 175 of Controller.php
* Controller->handleAction(HTTPRequest)
Line 129 of RequestHandler.php
* RequestHandler->handleRequest(HTTPRequest)
Line 122 of Controller.php
* Controller->handleRequest(HTTPRequest)
Line 29 of ModelAsController.php
* ModelAsController->handleRequest(HTTPRequest)
Line 44 of RootURLController.php
* RootURLController->handleRequest(HTTPRequest)
Line 277 of Director.php
* Director::handleRequest(HTTPRequest,Session)
Line 121 of Director.php
* Director::direct(/)
Line 118 of main.php

Can you please help me out?

Nice day, to everybody!


Forum Moderator, 5523 Posts

15 October 2009 at 7:52pm

$newssection = DataObject::get_one("News"); 

So you have a 'News.php' file which contains a News class right?


Community Member, 7 Posts

15 October 2009 at 7:53pm

I figured it out, it's working now! I shouldnt change the page types "ArticleHolder" and "ArticlePage" from
the function to the page names because SS find them out automatically.

But thanks for pointing it out to me: I was having a headache for 2-3 days trying to figure out why it was not
working to find out that it was a misplaced '}'.

Nice day to you!