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

Help with displaying HasManyComplexTableField data on frontend

Go to End



Community Member, 2 Posts

5 August 2010 at 1:32pm

I'm trying to filter data objects to display on the front-end of my home page. I created three functions within my HomePage controller to filter categories. However nothing is displaying on the frontend. My code below:


class Resource extends DataObject {
	static $db = array (
		'Name' => 'Text',
		'FileName' => 'Text',
		'Category' => "Enum('Program Details, Photograph Collections, Videos')"
	public static $has_one = array(
		'MyPage' => 'HomePage'

	public function getCMSFields_forPopup() {
		$fields = new FieldSet();
		$fields->push( new TextField( 'Name', 'Name' ) );
		$fields->push( new TextField( 'FileName', 'File Name' ) );
		$fields->push( new DropdownField('Category','Category', singleton('Resource')->dbObject('Category')->enumValues()) );
		return $fields;


class HomePage extends Page {

	public static $db = array(
	static $has_many = array (
		'Resources' => 'Resource'
	function getCMSFields() {
		$fields = parent::getCMSFields();

		$tablefield = new HasManyComplexTableField(
				'Name' => 'Name',
				'FileName' => 'File Name',
				'Category' => 'Category'
		$tablefield->setAddTitle('A Resource');

		$fields->addFieldToTab( 'Root.Content.Resources', $tablefield );
		return $fields;
class HomePage_Controller extends Page_Controller {

	public function ProgramDetails() {
		return $this->Level(1)->Resources("Category = 'Program Details'");
	public function PhotographCollections() {
		return $this->Level(1)->Resources("Category = 'Photograph Collections'"); 
	public function Videos() {
		return $this->Level(1)->Resources("Category = 'Videos'");

<% if ProgramDetails %>
	<% control ProgramDetails %>
	<% end_control %>
<% end_if %>