Figured it out at last - TinyMCE templates/snippets

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
geeves
Forum Members
Forum Members
Posts: 114
Joined: Wed Dec 03, 2008 4:56 am

Figured it out at last - TinyMCE templates/snippets

Post by geeves »

Hye guys.

I've been trying to figure this one out for a while but finally managed to get something working.

Templates in TinyMCE.

1. First, you need to enable the templates plugin in the TinyMCE module configuration (Extensions > TinyMCE WYSIWYG)
2. Go to the Plugins tab and check the templates plugin. Save plugins
3. Add the template plugin to a toolbar in the profiles tab. Save profile
4. Unless someone can get this working in the 'Extra configuration' section under 'Advanced':
    open the file: modules/TinyMCE/templates/tinyconfig.tpl

5. add the following code AFTER line 80 which looks like this:

Code: Select all

{if $extraconfig!=''}
  {$extraconfig}
{/if}

Code: Select all

{literal}
,template_cdate_classes : "cdate creationdate",
	template_mdate_classes : "mdate modifieddate",
	template_selected_content_classes : "selcontent",
	template_cdate_format : "%m/%d/%Y : %H:%M:%S",
	template_mdate_format : "%m/%d/%Y : %H:%M:%S",
	template_replace_values : {
		username : "Jack Black",
		staffid : "991234"
	},
	template_templates : [
		{
			title : "Sample snippet",
			src : "./tinymce_templates/test.htm",
			description : "Sample snippet"
		}
	]
{/literal}
6. Modify your own templates and location of templates within 'template_templates' (above).

The code above was taken from the TinyMCE wiki: http://wiki.moxiecode.com/index.php/Tin ... s/template

Replace with your own values/settings etc.

If anyone can do this in a cleaner and more efficient way, please let us know.
Ara Garabedian
Multimedia Designer / Developer
http://ara.ifky.com.au
superstoffe
Forum Members
Forum Members
Posts: 50
Joined: Fri Jan 16, 2009 1:07 pm

Re: Figured it out at last - TinyMCE templates/snippets

Post by superstoffe »

This works great, compared to putting it in the admin "extra configuration" atleast.

Got a little problem though. Can't seem to get more than one template to work?! And all the Jack Black jibberish, why is that needed? It doesnt seem to work without.
superstoffe
Forum Members
Forum Members
Posts: 50
Joined: Fri Jan 16, 2009 1:07 pm

Re: Figured it out at last - TinyMCE templates/snippets

Post by superstoffe »

Was a bit fast there  :D

This seems to work:

Code: Select all

{literal}
,template_cdate_classes : "cdate creationdate",
	template_mdate_classes : "mdate modifieddate",
	template_selected_content_classes : "selcontent",
	template_cdate_format : "%m/%d/%Y : %H:%M:%S",
	template_mdate_format : "%m/%d/%Y : %H:%M:%S",
	template_replace_values : {
		username : "Jack Black",
		staffid : "991234"
	},
	template_templates : [
		{
			title : "Template 1",
			src : "./modules/TinyMCE/templates/template1.html",
			description : "Template 1 example"
		},
		{
			title : "Template 2",
			src : "./modules/TinyMCE/templates/template2.html",
			description : "Template 2 example"
		}
	]
{/literal}
Jonny
Forum Members
Forum Members
Posts: 77
Joined: Sun Sep 24, 2006 10:49 am

Re: Figured it out at last - TinyMCE templates/snippets

Post by Jonny »

I prefer to avoid editing anything within the TinyMCE module's files, and instead use an external template list file, as described in the tinyMCE documentation.

The list file, list.php, is stored in a folder named user_templates in the root (I also put the templates in the same directory for convenience).

list.php contains:

Code: Select all

var tinyMCETemplateList = [
	// Name, URL, Description
	["Layout", "/user_templates/layout.html", "HTML Layout."],
	["Other", "/user_templates/other.html","Another template"]
];
Then in the Extra Configuration box of Extensions/TinyMCE WYSIWYG/Advanced enter the URL to the list file

Code: Select all

template_external_list_url :  '/user_templates/list.php'
Last edited by Jonny on Thu Mar 25, 2010 9:00 pm, edited 1 time in total.
KO
Power Poster
Power Poster
Posts: 562
Joined: Mon Nov 06, 2006 7:55 pm

Re: Figured it out at last - TinyMCE templates/snippets

Post by KO »

Steps 4-5 can done in TinyMCE "extra configuration" so no changes needed to any files. You just have to make it right or you might lose your editor :( Earlier versions of TinyMCE were very strick what you write on that box but latest versions (tried it with version that comes with 1.7) seems to be much more relaxed. One extra line break and editor was gone.

Here is one that makes 2 templates:

Code: Select all

template_templates : [{title : "Test template 1",
		src : "templatetest1.htm",
		description : "Description for test template 1"},
{title : "Test Testitemplate 2",
		src : "templatetest2.htm",
		description : "Description for test template 2"}]
Those templates "templatetest1.htm" and "templatetest2.htm" are now in webroot unless you change the path in src.
User avatar
micahgodbolt
Forum Members
Forum Members
Posts: 149
Joined: Thu Jul 29, 2010 11:09 pm

Re: Figured it out at last - TinyMCE templates/snippets

Post by micahgodbolt »

I created a detailed how to. You can find it at

http://forum.cmsmadesimple.org/index.php/topic,49098.0.html
Post Reply

Return to “Modules/Add-Ons”