HTMLEditorField on frontend


#1

Silverstripe Version: 4.3.2

Question:

I’m upgrading a SS3 site to SS4. This site has an area where non-CMS users can write descriptions in rich text.

I cannot find any information on how to get the HTMLEditorField to work on the front-end. Any advice?


#2

Give this a try:

These two will be needed in the controller for the page.

Requirements::javascript('silverstripe/admin:thirdparty/tinymce/tinymce.min.js');
Requirements::css('silverstripe/admin:client/dist/styles/editor.css');

You can add the fields to the form with a standard field method:
HTMLEditorField::create('Content')->setTitle('Content Editor Field'))

And you’ll need to add some JS to initialise the editor, eg:

tinymce.init({
        selector: 'textarea',
        skin: 'silverstripe',
        max_height: 250,
        menubar: false
});

#3

legend, works perfectly.

For future reference, you’ll likely want to disable the menu and status bars.

    <script type="text/javascript">
        tinyMCE.init({
            selector: 'textarea',
            skin: 'silverstripe',
            menubar: false,
            statusbar: false,
        });
    </script>