We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38121
    • 36 Posts
    I'm witnessing a super odd behavior in Revo 2.2.0-pl2:

    I use a snippet to inject some html before </body> with $modx->regClientHTMLBlock(); It worked great for months. Right now the html is injected *only* on the very first page load after clearing the site cache. On subsequent page loads no html is injected o_O The snippet wasn't edited since it last worked.

    Some help would be more than welcome.
    [ed. note: yogooo last edited this post 14 years, 8 months ago.]
      • 3749
      • 24,544 Posts
      What happens if you call the snippet uncached?

      [[!SnippetName]]



      ---------------------------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
      MODX info for everyone: http://bobsguides.com/modx.html
        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
        • 38121
        • 36 Posts
        It works.
        Wowhooo, celebration time laugh thanks Bob!

        The snippet is used to inject some html, both in place of the snippet call and before </body>. There's nothing dynamic in there. How come it needs to be called uncached? Really scratching my head on this one...
          • 3749
          • 24,544 Posts
          As I understand it, the snippet cache can only cache the *return value* of the snippet, and when the snippet is cached, that return value is pulled from the cache and the snippet doesn't actually execute, the regClient*() call isn't made, and the HTML or the page doesn't get modified.


          ---------------------------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
          MODX info for everyone: http://bobsguides.com/modx.html
            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
            So the first time the page is generated, the snippet runs and the HTML is inserted. The page is cached with the HTML. On subsequent loads from cache it should still be there, no?

            Something else must be at play here; it's working fine for me. [ed. note: sottwell last edited this post 14 years, 8 months ago.]
              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
              The page itself would have to be marked cacheable.

                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
                Do you mean that a snippet's output can be cached, while the page itself is not?
                  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 any element in Revolution can be cached or uncached independent of everything else -- even placeholders and language tags.



                  ---------------------------------------------------------------------------------------------------------------
                  PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
                  MODX info for everyone: http://bobsguides.com/modx.html
                    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
                    • 38121
                    • 36 Posts
                    Thanks for the explanation Bob. And yep, the resource is marked as cacheable.

                    While calling the snippet uncached works wonders, and as sottwell says, there must be something else at play. I used to call it cached on three different templates and it worked flawlessly. This morning it stopped working on the two other templates, so now I call it uncached everywhere... it works but it's weird that it stopped working all of a sudden (config didn't change, snippet didn't change either).

                    I looked for some documentation on regClient*() execution and caching, nothing found. Is there a way to trace the modx parser step by step to see what's happening?
                      • 3749
                      • 24,544 Posts
                      It's hard to trace things unless you run the whole site under a debugger, and that can be pretty tedious and hard to set up. You can look in the core/cache directory, though, and see what's being cached.


                      ---------------------------------------------------------------------------------------------------------------
                      PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
                      MODX info for everyone: http://bobsguides.com/modx.html
                        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