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.

Customising the CMS /

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

SS3 tinymce templates help


Go to End


2 Posts   2355 Views

Avatar
Harley

Community Member, 165 Posts

11 March 2013 at 2:57pm

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

Avatar
Optic Blaze

Community Member, 190 Posts

13 April 2013 at 10:34am

Edited: 13/04/2013 8:56pm

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