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

Adding ImageField to CompositeField

Go to End

2 Posts   2954 Views


Community Member, 17 Posts

27 February 2010 at 3:10am

I'm trying to have a two column layout where there would be editable title, editable HTMLText content and also a possibility to add an one image.

This is the way I'm trying to do:

 * Defines the ArticlePage page type
class HomePage extends Page {
	static $db = array(

		'ContentColumns' => 'HTMLText'


   static $has_one = array(

   function getCMSFields() {
		$fields = parent::getCMSFields();
		$multiColumnField = new CompositeField(
			new CompositeField(
				new TextField('Header1', 'Title'),
				new HTMLEditorField('Content1', 'Content'),
				new ImageField('ColumnImage1', 'Image')
			new CompositeField(
				new TextField('Header2', 'Title'),
				new HTMLEditorField('Content2', 'Content'),
				new ImageField('ColumnImage2', 'Image')
		$fields->addFieldToTab('Root.Content.Main', $multiColumnField, 'Content');
		return $fields;
class HomePage_Controller extends Page_Controller {

When I try to upload an image, it just doesn't show up. Could it be that the data type I'm trying to set is HTMLText? Any suggestions?

Thank You in advance!


Community Member, 545 Posts

27 February 2010 at 10:18am

I'm not sure if a composite field will do what you're looking for, but I've never used it.

What I can see is that you haven't defined DataBase fields and relations for any of your content. You need to write Header 1, Content1, ColumnImage1, Header2, Content2, and ColumnImage2 somewhere.

static $db = array ('header1' => 'Text', 'Content1' => 'HTMLText','header2' => 'Text', 'Content2' => 'HTMLText');
static $has_one = array ('Image' => "Image');

And I should warn you the I think the CMS still only supports one Image Object per page.