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

Displaying content from DataObject in .ss templates

Go to End

3 Posts   1062 Views

Fantastic Contraption

Community Member, 3 Posts

14 October 2010 at 4:54am

I've created a DataObject called SideModules for adding custom content to various pages around my SilverStripe site, but at the moment, I'm only using it on my StaffPage. I can create the modules fine in the admin interface, I just can't seem to get them to display in my templates. Just for reference, I'm using SilverStripe 2.4.1.


class SideModule extends DataObject
	static $db = array (
		'Title' => 'Text',
		'Content' => 'HTMLText'
	static $belongs_many_many = array(
        'StaffPages' => 'StaffPage'
	public function getCMSFields_forPopup()
		return new FieldSet(
			new TextField('Title'),
			new SimpleHTMLEditorField('Content')
class SideModule_Controller extends Page_Controller {


class StaffPage extends Page {
    static $db = array(); 
    static $many_many = array(
        'SideModules' => 'SideModule'

    function getCMSFields() {
      $fields = parent::getCMSFields();
      // Add a Data Object Manager to include content on the sidebar
      $fields->addFieldToTab("Root.Content.SideModules", new DataObjectManager(
			array('Title'=>'Title','Content' => 'Content'),

      return $fields;
class StaffPage_Controller extends Page_Controller {

<% if SideModules %>
        <% control SideModules %>
        <div class="section">
        <% end_control %> 
    <% end_if %>

So, everything works on the admin side of things as far as I can tell. I can add SideModules to a StaffPage template. I can re-order, edit and delete them. However, the SideModules control just doesn't output anything. It doesn't throw any errors or anything. Any ideas where I'm going wrong? There is also a StaffHolder page for displaying all StaffPage items, but I dont' think that has anything to do with the problems I'm having getting the content to display.


Forum Moderator, 4102 Posts

14 October 2010 at 5:12am

Yeah, you've kind of messed things up. I'm not sure what SideModule_Controller is, but it definitely doesn't belong there. DataObjects don't have controllers. That's why you need to do custom coding to get them to display like pages.

To manage the many_many in your StaffPage, you need a ManyManyDataObjectManager, not a regular DataObjectManager.

SilverStripe tips, tutorials, screencasts and more:

Fantastic Contraption

Community Member, 3 Posts

14 October 2010 at 6:00am

Cheers for the reply UncleCheese, your suggestions got me thinking about how I had set everything up and I've managed to fix everything. The many-many relationship was the wrong choice for one, so I've gone for one to many as it makes the most sense for what I need.