5121 Posts in 1527 Topics by 1119 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 277 Views |
-
SS3 tinymce templates help

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
- ');
-
Re: SS3 tinymce templates help

13 April 2013 at 10:34am Last edited: 13 April 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
| 277 Views | ||
|
Page:
1
|
Go to Top |


