We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 727
    • 502 Posts
    Sorry, if this has already been posted/suggested...

    Using chunks for TinyMCE templates keeps all the templating in the site manager for easy maintenance. TinyMCE templates make it easy to allow insertion of divs and spans in a consistent manner by content editors.

    Create a new resource/web page with the alias "getchunk", no template and the content:

    [!GetChunk!]


    Create a snippet called GetChunk with:

    <?php
    // get chunk name
    $name = isset ($name) ? $name : strip_tags(stripslashes($_GET['name']));
    // get chunk
    $output = $modx->getChunk($name);
    return $output;
    ?>


    Go to the configuration options for TinyMCE plugin and add "template" to Web Plugins and one of the button rows. Select the "custom" theme.

    Note from sharkbait: you also need to do this under Configuration -> Interface

    In the TinyMCE plugin custom parameters field add:

    template_external_list_url: "/templates.js"


    Create a new resource and set the content type to "text/javascript" and the alias to "templates.js". Disable TinyMCE for editing this document. Remove the template selection. Enter:

    var tinyMCETemplateList = [
      // Name, URL, Description
      ["Test Template", "/getchunk.html&name=test-template", "A template for testing"]
    ];


    Create a new chunk called "test-template" with some HTML.

    Now you should be able to choose "Test Template" in the templates list in TinyMCE. When selected it will insert the contents of the "test-template" chunk.

    Optional: it should be possible to have templates.js call a snippet that automatically builds the javascript template list from a set of chunks, perhaps with a specific prefix. This is left as an exercise for the reader. wink

    Andy
      • 26931
      • 2,314 Posts
      hey Andy,

      thanks for sharing! *bookmarked* will test this later smiley
        • 20413
        • 2,877 Posts
        Thanks for sharing! cool
          @hawproductions | http://mrhaw.com/

          Infograph: MODX Advanced Install in 7 steps:
          http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

          Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
          http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
          • 26931
          • 2,314 Posts
          Hey Andy,

          i followed the instructions, but TinyMCE doesn’t show the templates list - any ideas what i could have done wrong?

          calling mydomain/getchunk.html&name=test-template shows the chunk content perfectly

          *edit: YAY - it’s working!!
          Go to the configuration options for TinyMCE and add "template" to Web Plugins and one of the button rows. Select the "custom" theme.
          had to do that under configuration -> Interface smiley
            • 26931
            • 2,314 Posts
            just tested it with a wayfinder call in the chunk: ka-chiiiing smiley insert galleries here we come
              • 26931
              • 2,314 Posts
              Andy, from your initial thread:
              The problem is that TinyMCE adds paragraph tags around the chunks when they are added. Although this appears to display OK, I don’t like it.

              have a look at this thread -> http://modxcms.com/forums/index.php/topic,28908.0.html
                • 26931
                • 2,314 Posts
                another approach for TinyMCE’s insert template function (without snippets & chunks) can be found here -> http://modxcms.com/forums/index.php/topic,31097.msg188847.html#msg188847

                ...creating and managing the templates as chunks is more convenient though

                  • 21088
                  • 85 Posts
                  I have tried to follow your guide but there isnt any files i can browse when I click on the TinyMCE template button.

                  Where should i put the: template_external_list_url: "/templates.js" line?

                  Im using the the latest version of ModXcms and its using TinyMC version tinymce3241.

                    • 20413
                    • 2,877 Posts
                    Very nice!!!

                    @need4speed
                    In MODx 1.0.2 I had to change the style to custom + adding template plugin/button in manager configuration
                    page
                    in addition to the plugin config.

                    // My "Custom Parameters" field in TMCE plugin config:
                    template_external_list_url: "/templates.js",
                    forced_root_block : false,
                      @hawproductions | http://mrhaw.com/

                      Infograph: MODX Advanced Install in 7 steps:
                      http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

                      Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
                      http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
                      • 21088
                      • 85 Posts
                      what does the line: forced_root_block : false, do ? smiley