Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Allan Joey Laluan 24 posts 105 karma points
    Mar 09, 2014 @ 05:49
    Allan Joey Laluan
    0

    How to add tinymce Templates in v7

    Hi gurus,

    How can I add templates in tinymce in umbraco v7? I tried the post from here: http://our.umbraco.org/wiki/how-tos/enabling-the-'template'-plugin-for-tinymce it works in v6 but not in v7 anymore.

    Hope you can provide a tutorial or some help in attaining this goal. Thanks in advance.

    Cheers,

    Allan

     

  • gilad 185 posts 425 karma points
    Mar 09, 2014 @ 16:30
    gilad
    2

    Hello Allan.

    I got it work.
    I dont know if this is the "Right way" to do that , while you have to change "umbraco.controllers.js" inside "Umbraco/Js/"
    but it is work. :) 
    As i say - I'm pretty sure it isn't the "Right way".. but for now it's seems like the "umbraco.controllers.js" doesn't do anything with the <customConfig> section.

    Here's what i do :

    1) Like the description in the post : http://our.umbraco.org/wiki/how-tos/enabling-the-'template'-plugin-for-tinymce
    Open "/config/tinyMceConfig.config" and add the following sections.

    Add this to <commands> ( only change the icon url becuse 'templae.gif' isn't there )

    <command>
           <umbracoAlias>Templates</umbracoAlias>
           <icon>images/editor/skin.gif</icon>
           <tinyMceCommand value="" userInterface="true" frontendCommand="template">template</tinyMceCommand>
          <priority>76</priority>
    </command>


    Add this to <plugins>

    <plugin loadOnFrontend="true">template</plugin>


    Add this to <customConfig> ( Here you have to change the structure + the 'src' to 'url' + you must set the key to 'tempaltes')

    <config key="templates">
             [{
             "title" : "Two Column",
             "url" : "/editorTemplates/TwoCol.html",
             "description" : "Two Column layout"
             },
             {
             "title" : "Three Column",
             "url" : "/editorTemplates/ThreeCol.html",
             "description" : "Two Column layout"
             }]
    </config>


    2) Open "/Umbraco/Js/umbraco.controllers.js" and add the following

    On row 4764 after:
    "tinyMceService.configuration().then(function(tinyMceConfig){"
    add this : 

    var templates = "";
    if (tinyMceConfig.customConfig.templates) {
        templates = JSON.parse(tinyMceConfig.customConfig.templates);
    }

    On row 4836 ( tinymce init function) -  "tinymce.init({.... "
    add this to the function object

    templates : templates,


    It should look like this:

    $timeout(function () {
                           tinymce.DOM.events.domLoaded = true;
                           tinymce.init({
                               mode: "exact",
                               elements: $scope.model.alias + "_rte",
                               skin: "umbraco",
                               plugins: plugins,
                               templates : templates,
       ........ 


    Hope that help,
    Cheers.

     

  • gilad 185 posts 425 karma points
    Mar 09, 2014 @ 16:32
    gilad
    0

    And dont forget to 
    "Recycle application pool / touch web.config to see the changes in the tinyMceConfig.config propogated."

  • uxbridge 9 posts 49 karma points
    Mar 13, 2014 @ 00:58
    uxbridge
    0

    I was also surprised to find the templates functionality no longer worked in v7.

    Potentially resolved in 7.1, although I've not had a chance to test the beta yet.

    http://issues.umbraco.org/issue/U4-4031

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    May 01, 2014 @ 12:57
    Jan Skovgaard
    0

    @Gilad - Must the templates be saved to a specific folder in order to be picked up? I'm using 7.1.1 and have followed the original guidelines from the old wiki - The template icon is added but when I click it in the rich text editor I just get a message saying "no templates defined".

    Not sure where it looks for the template but I have just placed my template in the /config/ folder for now...

    My configuration is like this

    Command

    <command>
        <umbracoAlias>Templates</umbracoAlias>
        <icon>images/editor/template.gif</icon>
        <tinyMceCommand value="" userInterface="true" frontendCommand="template">template</tinyMceCommand>
        <priority>75</priority>
    </command>
    

    Plugins

    <plugin loadOnFrontend="true">template</plugin>
    

    Custom config - The tricky part where something is perhaps wrong, or not supported by the core.

    <customConfig>
        <config key="nonexisting">
            <![CDATA[',
                templates:[
                    {
                        title : "Two Column",
                        url : "edit-field.html",
                        description : "Two Column layout"
                    }]
            ]]>
        </config>
    </customConfig>
    

    Does anyone know if I need to change something in the configuration? Perhaps I should just submit a bug but would like checking before doing so.

    Cheers, Jan

  • gilad 185 posts 425 karma points
    May 01, 2014 @ 22:07
    gilad
    1

    Hi Jan.

    Just try this on 7.1.1
    Maybe there is way to do it through the <customConfig> only, but i can't find it yet.
    Meanwhile, i mange to get it work like this:

    "/Umbraco/Js/umbraco.controllers.js" -  on row 5383,
    Befor : if(tinyMceConfig.customConfig){
    Add this: 

    if (tinyMceConfig.customConfig.templates) {
               tinyMceConfig.customConfig.templates = JSON.parse(tinyMceConfig.customConfig.templates);
    }

     

    Then, change your config under <customConfig> on tinyMceConfig.config like this :

    <config key="templates">
             [{
            "title" : "Two Column",
    "url" : "/editorTemplates/TwoCol.html",
    "description" : "Two Column layout"
             }]
    </config>
    • Key must be "templates"
    • Use the path to template file , not only the name
    • Add double quotes to the keys of the object("title" , "url" , "description")
    Hop that help,
    Cheers.
  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    May 01, 2014 @ 22:19
    Jan Skovgaard
    0

    Hi Gilad

    Thanks for your answer. Will give it a go tomorrow at work.

    In regards to the path...is /editorTemplate/ just a folder you're using as an example or does it exist in the file system somewhere? I'm in doubt about wether I could just reference any folder I'd like to be honest.

    Cheers, Jan

  • gilad 185 posts 425 karma points
    May 01, 2014 @ 23:53
    gilad
    0

    Hi Jan.

    The path is for the example.

    Cheers

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    May 02, 2014 @ 10:08
    Jan Skovgaard
    0

    Hi Gilad

    Awesome! Got it working now...Think I'll create a pull request for this change :)

    Cheers, Jan

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    May 02, 2014 @ 11:47
    Jan Skovgaard
    0

    Hi Gilad...

    One more question though...how would you enable the options to for instance manage with and height on the template window? as listed here http://www.tinymce.com/wiki.php/Plugin:template

    /Jan

  • Allan Joey Laluan 24 posts 105 karma points
    May 11, 2014 @ 16:52
    Allan Joey Laluan
    101

    Hi Gilad,

    I tried your solution in v7.1.2 but I'm having this error:
    http://localhost/umbraco/[%7B%20%20%20%20%20%20%20%20%20%20%20%20%22title%22%20:%20%22Two%20Columns%22,%20%20%20%20%20%20%20%20%20%20%20%20%22url%22%20%20%20:%20%22/templates/twocol.html%22,%20%20%20%20%20%20%20%20%20%20%20%20%22description%22%20:%20%22Two%20Column%20Layout%22%20%20%20%20%20%20%20%20%20%20%7D]

    Below if my settings:

    CustomConfig


    [{
    "title" : "Two Columns",
    "url"   : "/templates/twocol.html",
    "description" : "Two Column Layout"
    }]

    In /Umbraco/Js/umbraco.controllers.js file
    I add this in line 5457 after angular.extend(baseLineConfigObj, tinyMceConfig.customConfig)

    if(tinyMceConfig.customConfig.templates){
                tinyMceConfig
    .customConfig.templates = JSON.parse(tinyMceConfig.customConfig.templates); 

    Regards,

    Allan

  • nik 1 post 24 karma points
    May 27, 2014 @ 20:18
    nik
    3

    Allan, I had the same problem in 7.1.3 and found that the <config key="templates"> is expecting a URL to a config value. I updated it to be

    <config key="templates">/App_Plugins/TinyMceTemplates/templates-config.html</config>

    And then dropped

    [
        {"title": "Some title 1", "description": "Some desc 1", "content": "My content"},
        {"title": "Some title 2", "description": "Some desc 2", "url": "/App_Plugins/TinyMceTemplates/development.html"}
    ]

    into /App_Plugins/TinyMceTemplates/templates-config.html

    This worked for me and I didn't have to make any changes to the controller. Plus, you don't have to touch web.config every time you make a change or add a template.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    May 28, 2014 @ 08:59
    Jan Skovgaard
    0

    Hi Nik

    Thanks for that tip - I'm going to try it out as well.

    So is this really all you did to enable the templates in tinyMce? Once the templates-config.html file is in place you did not have to do anything else?

    /Jan

  • Ben Tice 31 posts 131 karma points
    Jul 14, 2014 @ 00:53
    Ben Tice
    0

    Thank you nik! Was completely pulling my hair out with this one on v7.1.4!

  • Bruno Olsen 75 posts 316 karma points
    Aug 26, 2014 @ 14:29
    Bruno Olsen
    0

    Ok, I used nik's solution on two 7.1.4 sites successfully, but it seems this changes for almost each new version at the moment!?! In 7.1.5 I get the the icon on the editor, on hover it presents the right tool tip, on click however, nothing happens... Anyone know how to do it in Umbraco 7.1.5? Or anyone know that this method should work in 7.1.5?

  • Proxicode 127 posts 323 karma points
    Jun 11, 2015 @ 19:17
    Proxicode
    0

    All of the contributions on this thread helped get me going! Thanks to all of you :-)

  • _o_utofbounds 2 posts 72 karma points notactivated
    Jan 09, 2019 @ 14:14
    _o_utofbounds
    0

    this worked for me with 7.11.1 https://www.wiliam.com.au/wiliam-blog/adding-enhanced-styling-to-the-umbraco-tinymce-editor no need to change anything in the controllers.js however i had to enable the Templates toolbar icon in the Richtext editor Data Type to make it visible in the interface

Please Sign in or register to post replies

Write your reply to:

Draft