Jump to:

3444 Posts in 1030 Topics by 871 members

Template Questions

SilverStripe Forums » Template Questions » What field type should I use for rich text?

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

Page: 1
Go to End
Author Topic: 2019 Views
  • ianpiper
    Avatar
    Community Member
    32 Posts

    What field type should I use for rich text? Link to this post

    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.
    --

  • ianpiper
    Avatar
    Community Member
    32 Posts

    Re: What field type should I use for rich text? Link to this post

    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;
       }
       
    }

    2019 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.