We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4055
    • 7 Posts
    Does anyone know if you can call a Snippet from an external PHP file?

    I want to use a snippet as a configuration file for a PHP code base that exists outside of MODx but exist in a folder on the same site.
      Bret Bouchard
      518 Designs
      http://518designs.com
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Well, you could get the snippet code from the database and run it through the eval() function.

      You also might be able to include() it as a URL if you put the snippet call as the only content of a document with a template of ’blank’. That would require having allow_url_inlcude and allow_url_fopen in your php.ini.

      http://il2.php.net/manual/en/function.include.php (scroll down a bit to the relevant paragraph)
      If "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be included using a URL (via HTTP or other supported wrapper - see List of Supported Protocols/Wrappers for a list of protocols) instead of a local pathname. If the target server interprets the target file as PHP code, variables may be passed to the included file using a URL request string as used with HTTP GET. This is not strictly speaking the same thing as including the file and having it inherit the parent file’s variable scope; the script is actually being run on the remote server and the result is then being included into the local script.
        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