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:

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

DataObjects as Pages does not work :<

Go to End

3 Posts   1144 Views


Community Member, 14 Posts

22 May 2012 at 1:31am

Hello SilverStripe folks,

I've got a newsarticle.php page and a newsarticleholder.php.

This is my NewsArticle.php

class NewsArticle extends DataObjectAsPage {

//The class of the page which will list this DataObject
static $listing_class = 'NewsArticleHolder';
//Class Naming (optional but reccomended)
static $plural_name = 'NewsArticles';
static $singular_name = 'NewsArticle';

static $db = array (
'Title' => 'Varchar(255)',
'Date' => 'Date',
'Author' => 'Text',
'Content' => 'HTMLText',

static $has_one = array (
'NewsHolder' => 'NewsArticleHolder',

//Summar fields
static $summary_fields = array(

function fieldLabels($includerelations = true) {
$labels = parent::fieldLabels($includerelations);

$labels['Title'] = _t('newsarticle.TITLE', 'Titel');
$labels['Date'] = _t('newsarticle.DATE', 'Datum');
$labels['Author'] = _t('newsarticle.AUTHOR', 'Auteur');
$labels['Content'] = _t('newsarticle.CONTENT', 'Niewsbericht');
return $labels;

function getCMSFields() {

$fields = new Fieldset();
$fields->push(new TextField('Title','Titel'), 'Content');
$fields->push($dateField = new DateField('Date','Datum'), 'Content');
$dateField->setConfig('showcalendar', true);
$dateField->setConfig('dateformat', 'dd/MM/YYYY');

$fields->push(new TextField('Author','Auteur'), 'Content');

$fields->push(new HtmlEditorField("Content", _t('SiteTree.FOO', "Content", PR_MEDIUM, 'HTML editor title')));

return $fields;


and this is my NewsArticleHolder.php


class NewsArticleHolder extends DataObjectAsPageHolder {

static $has_many = array (
'NewsArticles' => 'NewsArticle',

public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldsToTab("Root.Content.Nieuws", new DataObjectManager($this, 'NewsArticles', 'NewsArticle'));

return $fields;

class NewsArticleHolder_Controller extends DataObjectAsPageHolder_Controller {
//This needs to know be the Class of the DataObject you want this page to list
static $item_class = 'NewsArticle';
//Set the sort for the items (defaults to Created DESC)
static $item_sort = 'Title ASC';


So my CMS just works fine, can add newsitems but when im on the newspage,
it wont show my newsitems :(

This is my

<div class="typography">
<% if Level(2) %>
<div class="breadcrumbs">
<% end_if %>
<div class="articles">
<ul id="NewsList">
<% control NewsArticles %>
<% end_control %>

Please help me guys!! I have no idea what i'm doing wrong, and im quite new to this....


Tim Snadden

Community Member, 32 Posts

22 May 2012 at 8:08am

If you are using the Data Objects as Pages module I believe the Controller method you need in the template is 'Items' for the listing page and 'Item' for the individual news article.

Tim Snadden

Community Member, 32 Posts

22 May 2012 at 8:11am

This article by the author of the module gives pretty good instructions on how to use it.