We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6038
    • 228 Posts
    I've created a plugin to help me load a chunk of html from a file, whose location is taken from a tv value, and is inserted into the document.

    My plugin is executed 'OnLoadWebDocument', and works great for including embedded css or js by using the $modx->regClientStartupScript() method. Every document in my site has access to this tv, which i can fill in with a filename path to a html file that will load it and insert it into the head of my document. 'Well why don't you just use a chunk?' I hear you ask. Some of the files are long javascript files which I like in my text editor for the syntax highlighting, making it easier for editing.

    My problem is that I can't use placeholders in the file I am using. If I change the system event to 'OnWebPagePrerender' then the regClientStartupScript method doesn't seem to work.
    How can i put placeholders in my files, and have the plugin read and insert them using the regClientStartupScript method, and still get the placeholders parsed?
      • 3749
      • 24,544 Posts
      If I'm understanding you, I think the most straightforward solution is to get the file with file_get_contents(), replace the placeholder(s) yourself with str_replace(), then call regClientStartupScript().


        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
        • 6038
        • 228 Posts
        Hmm yes - thanks for the reply Bob - I came to the same conclusion in the meantime also.
        So, to confirm I understand it - does parsing of placeholders take place before 'OnLoadWebDocument', and that is why mine do not get parsed? (I'm only using a meek little '[(base_url)]' in this example - not a custom value)

        I wish there was a flowchart that showed when all the system events get executed, in the context of requesting a url...
          • 3749
          • 24,544 Posts
          Here's my understanding of the sequence:

          OnHandleRequest — Fires when any request for a resource is received in the front end.

          OnWebPageInit — Fires after determination that the site is online and the requested resource is located.

          OnLoadWebDocument — Fires after the requested resource is loaded, but before it is parsed.

          OnParseDocument — Fires just before the MODX tags are processed.

          OnWebPagePrerender — Fires just before a completed web page in the front end is sent to the browser, after all tags have been processed.

          OnWebPageComplete — Fires just after a web page has been sent to the browser and the processed resource is saved to the cache.
            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
            • 6038
            • 228 Posts
            Thats a helpful list - thanks