We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 45011
    • 2 Posts
    I've tried but all that is output is the actual snippet call text. I've also tried to call via a php page but I get parsing errors because of the '&' character ( etc. ) . I did finally manage to call a snippet by loading $modx up externally and calling the snippet directly using 'runSnippet' but that was a lot of work.

    Do I need to call snippets from chunks. None of the tutorials or docs have made this clear to me.

      • 28042 ☆ A M B ☆
      • 24,524 Posts
      To call a snippet you have to have MODx to run it. Depending on the snippet code, you may or may not be able to simply use the snippet code elsewhere. If it uses the MODx APIs, you need to load MODx. There are three ways you can do this:
      http://rtfm.modx.com/revolution/2.x/developing-in-modx/other-development-resources/loading-modx-externally
        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
        • 45011
        • 2 Posts
        Thank you but I think it is not quite what I'm looking for. I'm interested in calling ( maybe calling is not the right word ) a snippet from a web page like...:

        [[Date]]

        or

        [[rssFeed ....]]


        as I said in my post : I've already called a snippet from PHP by loading the modx object and using 'runSnippet' . I've been able to make some progress. It seems that if I put the code in a resource ( rather than in a file ) then the snippet will get called. I guess that html files in the file system will not call a snippet.

        One thing that is bothing me is that I am able to load the 'Home' resource ( alias : index.html ) but can not load any other resources
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Since the snippet tags are unique MODx constructs - placeholders for various types of dynamic content - they mean nothing without the MODx parser to process them. MODx sees the snippet tags, and includes the snippet's cache file, like any other PHP include directive, except for some JSON-encoded metadata in the file that MODx parses. If it's not in the cache, then MODx fetches it from the database.

          Every single page you access using MODx is generated from the index.php file. It requires web server URL rewrites to convert "mypage.html" to "index.php?q=mypage.html", which MODx then processes to determine which resource has the alias of "mypage". Different web servers have different ways of accomplishing this; the most common Apache web server uses mod_rewrite with the rewrite directives in the .htaccess file.

            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