We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12151
    • 115 Posts
    hi guys ...
    how and where can i add my own custom php functions into the modx framework?
    and what would be the syntax to access one of these functions from within a snippet?
    thanks smiley
      • 10487 MODX Staff
      • 1,535 Posts
      Garry Nutting Reply #2, 19 years ago
      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

        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 12151
        • 115 Posts
        nice and easy! thanks smiley