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.

Template Questions /

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

What field type should I use for rich text?


Go to End
Reply


2 Posts   2384 Views

Avatar
ianpiper

Community Member, 32 Posts

25 March 2009 at 12:43am

Hi,

I want to add another field to my Content tab in the CMS editor. I would like it to have rich text like the Content field. What field type should I be defining in the class for $db and in getCMSFields? I can't find anything like RichTextField - is this field type available?

The reason I don't want to just use the Content field is that I want to make a teaser to use elsewhere and want to control case by case precisely what is in the teaser, including rich text (which is why I don't want to use$Description.LimitWordCount(xx)).

Thanks for any advice,

Ian.
--

Avatar
ianpiper

Community Member, 32 Posts

25 March 2009 at 2:50am

I figured it out: if anyone else is interested, the type to use in the class is "HTMLText", and the type to use in getCMSFields is "HTMLEditorField", like so:

class ContentBlockPage extends Page {
static $db = array(
'ColumnRef' => 'Text',
'RowNumber' => 'Int',
'BlockColour' => 'Text',
'TeaserText' => 'HTMLText'
);
static $has_one = array(
'TeaserImage' => 'Image'
);

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new TextField('ColumnRef'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new NumericField('RowNumber'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('BlockColour'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new HTMLEditorField('TeaserText'), 'Content');
$fields->addFieldToTab('Root.Content.Images', new ImageField('TeaserImage'));
return $fields;
}

}