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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

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

Custom fields - HTMLText


Go to End


3 Posts   1740 Views

Avatar
estheblessed

Community Member, 3 Posts

24 May 2016 at 11:28pm

Hi,

I am trying to add a second content area using the following:

<?php
class Publication extends Page {

private static $db = array (
'SideInfo' => 'HTMLText',
);

public function getCMSFields() {
$fields = parent::getCMSFields();

$fields->addFieldToTab("Root.Content.RightContent", new HTMLEditorField('SideInfo'));

return fields;
}

}
class Publication_Controller extends Page_Controller {
}

But when I try to add a new page of that type, it creates the page but I get the message 'Internal server error'. So I am assuming there is something wrong with that code above ^

Many thanks in advance

Avatar
Friizu

Community Member, 17 Posts

26 May 2016 at 10:42pm

Should work:

<?php
class PublicationPage extends Page {
private static $db = array(
   'SideInfo' => 'HTMLText'
);		
private static $has_one = array(
);
   public function getCMSFields() {
   $fields = parent::getCMSFields();
	 $fields->addFieldToTab("Root.Content.RightContent", new HTMLEditorField('SideInfo'));
   return $fields;
   } 
}
class PublicationPage_Controller extends Page_Controller {
}

And dev/build?flush=all after u have changed code.

Avatar
Vix

Community Member, 60 Posts

13 June 2016 at 4:28pm

You might need to change:

$fields->addFieldToTab("Root.Content.RightContent", new HTMLEditorField('SideInfo'));

to

$fields->addFieldToTab("Root.Main", new HTMLEditorField('SideInfo'));

This will put it on the main tab where the content and title are normally located.