We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6228
    • 249 Posts
    I’ve been racking my brains trying to figure out how to prepopulate the RTE content area with some ’starter html’ when a new page is created.

    For example, the starter html could be a basic table with rows and columns preloaded into the editor, so the user immediately has a framework in place to begin creating content. I know it’s possible to do *something* like this with Tiny templates, but it’s an additional step I’m trying to avoid to keep things simple.

    As far as I know, one way to achieve this is to create a plugin that triggers on [tt]onDocFormPrerender[/tt] and injects javascript into the head when [tt]$modx->resource[/tt] is null.

    Where I am at a loss is how to do this without hacking the Tiny plugin. So far, the only way I can see how to achieve this is to edit [tt]core/components/tinymce/templates/script.tpl[/tt] and add an event listener with a custom handler that fires on [tt]onLoadContent[/tt]. It seems overly convoluted to me.

    Is there an easier way?

    This is for TinyMCE 4.1.2-pl on Revo 2.0.7-pl
      lo9on.com

      MODx Evolution/Revolution | Remote Desktop Training | Development
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      If this is something you want for all resource content, you could go into the database and edit the content field to have a default.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 6228
        • 249 Posts
        Quote from: sottwell at Feb 12, 2011, 02:25 AM

        If this is something you want for all resource content, you could go into the database and edit the content field to have a default.

        You know, I never would have thought of that. Brillant!

        But I’m going to resist marking this post as resolved, because it would still interest me on doing this without cracking open the database.

        Thanks a bunch, Susan.
          lo9on.com

          MODx Evolution/Revolution | Remote Desktop Training | Development
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          With Revo it should be possible to make an adjustment to the resource editing form from a plugin. I believe that the form is available for customization at at least one point before being sent to the server. Something like the documentObject when parsing a resource.

          With Evo it would require javascript to meddle with the content field in the user’s browser since the form is generated and immediately echoed bit by bit in the .php file; you either add something before the form is started or after it’s finished, there’s no way to do anything to it in between. Hence ManagerManager.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 3749
            • 24,544 Posts
            I think might work to edit resource/create.tpl (if you could find it). wink

            There may also be a placeholder in that tpl that you could set in a plugin tied to OnWebPagePrerender. The Resource object is not available in OnWebPagePrerender, but it looks like the return value of any plugins tied to it is used.

            Also, the resource/create processor uses $scriptProperties[’ta’] to set the content, so if you could set that in the right place, it might make it through. The $_POST variables are no longer used, so it probably wouldn’t work to set it there.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              That "ta" field name is an artifact from the beginnings of Etomite; I’m not quite sure why the content field was given that name. "textarea" maybe?
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 6228
                • 249 Posts
                Thanks for the follow-ups, Bob, Susan. Both of you put me on the right path.

                This is what is working for me so far:
                Ext.onReady(function() {		   
                	Tiny.config.setup = function(ed) {
                		ed.onInit.add(Tiny.onLoad);
                		ed.onKeyUp.add(Tiny.onChange);
                		ed.onChange.add(Tiny.onChange);
                		ed.onPostRender.add(efxStarterHTML);
                	}; 
                });
                function efxStarterHTML() {tinyMCE.execCommand('mceInsertContent', false, '<p>Hello World</p>'); }


                The plug-in is triggered on [tt]onDocFormPrerender[/tt] and sends the above javascript code to [tt]error->output()[/tt].

                Now all I have to do is debug, fine-tune it to only trigger on a null Resource, tie the starter html to a chunk or resource, then package it up and share it with the world smiley

                Mike
                  lo9on.com

                  MODx Evolution/Revolution | Remote Desktop Training | Development