Sometimes when working with a lot of snippets, I hate having to go back and forth to the manager from my IDE to cut and paste changes back and forth. A technique I’ve adopted for dealing with this is to include the code for my snippets from an external file. This has the added benefit of reducing the amount of content being kept in memory by the parser for every request to your site, by simply reducing the amount of actual snippet content. And in future releases, all snippets will actually become external files included only as needed by the parser.
So, here’s an example of including snippets this way:
[*] Create a directory for your snippets (i.e. identify a location where you will keep your snippet code). I typically define snippet directories for specific projects or groups of snippets, e.g. /assets/snippets/myproject/
[*] Use a simple naming convention to easily identify your snippet files, e.g. /assets/snippets/myproject/MySnippet.snippet.php, where MySnippet is the actual name of your snippet.
[*] Copy your snippet code into the file (don’t forget to add the php tags <?php ?>)
[*] Create your snippet (or edit an existing one you want to convert to use this method) in the manager, e.g. MySnippet, with the following code:
return include_once($modx->config['base_path'] . 'assets/snippets/myproject/MySnippet.snippet.php');
Please note that this assumes your snippet is returning content (e.g. return $content;) -- you may want to leave out the return and have your included code echo the content, depending on your requirements; otherwise, the include will return a true/false response in your content. Or you can just add return ’’; at the end of your snippet.
Also note you may need to do an include vs. include_once, depending on what your code does.
Once setup, you can now edit the snippet file( s ) and see changes instantly (or edit locally and upload via FTP to see changes on a remote site).