We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18270
    • 68 Posts
    Hi All,
    Interesting issue I am stuck with here.
    I have a snippet that outputs a few counters in the top of my template (basically just after body open).

    The problem I have is that the values that are displayed by this snippet can change further down in the template if certain conditions occur.
    <body>
    [[!showCount]]
    [[!processPostDataAndUpdateCount]]
    </body>
    

    Basically I want the process snippet to do its work and then have the showCount snippet show the count after it has been processed further down in the template.

    Is there any way to force the showCount snippet to run after all others? Sadly it is not possible for me to move the count snippet after the process snippets due to 3rd party architecture.

    Any suggestions welcome. Perhaps I am not thinking about the problem in the right way.

    Thanks!
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You could have the snippet run after the post-process snippet but put its output into a placeholder, then put the placeholder into the page wherever you like.


      Turn it into a plugin that runs at the end of parsing using the OnWebPagePreRender event. Depending on the exact circumstances, your existing snippet could output some very distinctive string like ######## so the plugin would just get the count value, then str_replace the ######## with the count. [ed. note: sottwell last edited this post 14 years, 5 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
        • 18270
        • 68 Posts
        Oh wow.... I feel a little silly not having thought of that before. I think the placeholder might be easier. Otherwise it is a bit difficult to pass attributes into the count snippet.

        Both good ideas though. Thanks for that!