We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27519
    • 275 Posts
    Hi,

    Coming from a Joomla environment I was used to having all php code for customisation outside the database, just sitting as plain files in the file system.

    Modx has a different approach, at least for snippets. As far as I know, snippets are stored in the database and evaluated when called upon.

    After about a month working with modx, I find that developing more complex snippets is very cumbersome process. The modx editor is not really equipped for this.

    What I do now, is develop complex snippets as classes outside modx and use the snippet as a mere wrapper. This allows me to develop the class using a decent development environment.

    Would that be an advisable approach?
      MODx Revolution / MAMP / OS X
      • 3749
      • 24,544 Posts
      Yes, many people do that. If you’re using MODx Revolution, you could also check out the CodeMirror plugin which provides rudimentary code editing for snippets.
        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
        • 17499 ☆ A M B ☆
        • 872 Posts
        As BobRay as said, many people do that.

        Take a look at the many available snippets. For Revo, most of the big snippets are used to instantiate the appropriate class which is not stocked in the database.

        There is also an helper to load class files: http://rtfm.modx.com//display/XPDO10/xPDO.loadClass
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Indeed, any snippet more than a few lines should be developed this way. Basic initialization (checking for parameter settings, for example) and then include the main file for the snippet. The Jot snippet is a good example for Evo.
            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
            To clarify my original post, you can not only put the class in a file, but the snippet as well so the snippet in the DB can be a single line:

            return include 'path/to/snippet/code';
              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
              • 27519
              • 275 Posts
              Quote from: BobRay at Sep 01, 2010, 12:01 AM

              To clarify my original post, you can not only put the class in a file, but the snippet as well so the snippet in the DB can be a single line:

              return include 'path/to/snippet/code';


              Excellent! Thanks
                MODx Revolution / MAMP / OS X