Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » SS3 tinymce templates help

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

Page: 1
Go to End
Author Topic: 532 Views
  • Harley
    Avatar
    Community Member
    153 Posts

    SS3 tinymce templates help Link to this post

    Hello,

    I'm currently trying to create a tinymce 'templates' module to allow html templates and snippets in your content.

    I refer to this article from 2010 http://internetstate.info/2010/12/07/tinymce-templates-in-silverstripe-htmleditorfield-and-simpletinymceeditor-dataobject-manager/

    I have the template button working fine, but as it retrieves the html file it is inserting my page content and not the html I've selected.

    I'm running out of ideas here but it would be nice to finish this off.

    Here is my code:

    tinymce-templates/code/tinymceTemplates.php:

    <?php

    class tinymceTemplates extends LeftAndMainExtension{

    function init() {

       parent::init();
       //tinymce plugins   
       HtmlEditorConfig::get('cms')->enablePlugins('template');
       HtmlEditorConfig::get('cms')->insertButtonsAfter('tablecontrols','template');
       HtmlEditorConfig::get('cms')->setOption('valid_elements','*

    • ');
         HtmlEditorConfig::get('cms')->setOption('extended_valid_elements','*
    • ');
         HtmlEditorConfig::get('cms')->setOptions(array('template_templates' => array(
         array(
            'title'=>'Two columns','src'=>'$BaseURL/tinymceTemplates/templates/columns-2.htm','description'=>'A two column layout'
            )
         )));
         }
      }


    tinymce-templates/templates/columns-2.htm:

    <div class="row">
       <div class="2-col">column one</div>
       <div class="2-col">column two</div>
    </div>


    mysite/_config.php:

    LeftAndMain::add_extension('LeftAndMain','tinymceTemplates');

    Regards

  • Optic Blaze
    Avatar
    Community Member
    150 Posts

    Re: SS3 tinymce templates help Link to this post

    Hi there,

    There is a easier way to do this.

    1) Insert the following code into you _config.php file:

    ----------------------------------------------------------------------------------

    // Enable template plugin in the WYSIWYG editor//
    HtmlEditorConfig::get('cms')->enablePlugins('template');
    HtmlEditorConfig::get('cms')->insertButtonsAfter('tablecontrols', 'template');

    //Specify location of your snippets//
    HtmlEditorConfig::get('cms')->setOptions(array('template_templates'=>array(
    array('title'=>'3 Columns','src'=>'mysite/templates/3col.html','description'=>'3 Column template'),
    array('title'=>'2 Columns','src'=>'mysite/templates/2col.html','description'=>'2 Columns template'),
    array('title'=>'1 Column','src'=>'mysite/templates/1col.html','description'=>'1 column template'),
    )));
    -----------------------------------------------------------------------------------

    2) Then under the mysite folder create a folder called templates.
    3) In the templates folder create your snippet html files...in this example they should be called 3col.html, 2col.html, 1col.html
    4) Run a dev build and refresh the cms
    5) In the CMS you should now have a new button (see screen shot) when you click it, it will give you a drop down menu of your snippets that you can insert anywhere in the document

    Attached Files
    532 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.