Easiest way is to create yourself a php file containing all your functions for that particular snippet, save it in a subfolder under ’assets/snippets’ then include the file in your snippet code using the
include_once() PHP function somewhere near the top (before you make reference to any of the functions within your include file)
It’s as simple as that, there’s no special MODx functions that you need to use to do this. You can use MODX_BASE_PATH to provide the path to your website root. So a typical include in a snippet would become (and let’s say it contains a function called
foo):
include_once MODX_BASE_PATH.'assets/snippets/mySnippet/functions.php';
// can now use the foo() function
$myVar = foo();
Hope that helps,
Garry