We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8779
    • 93 Posts
    I’ve created some snippet, but I don’t know the folder location of this snippet.
    Where is the location of that snippet file? I want to include some of this file, but I don’t know the path.
    thanks before
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Snippets are stored in the database, in the site_snippets table. A copy is also stored in the assets/cache/siteCache.idx.php file. But for creating and editing snippets, you use the manager, in Resources -> Manage Resources, the Snippets tab. You can create a new snippet or edit an existing one from the list.

      A snippet itself can be as simple as a single line to include an external .php file. The location of the .php file is up to you. Normally such external files are stored in the assets/snippets/your-snippet-name folder, but you can put them wherever you want as long as the correct path is specified in the include line in the snippet.
        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
        • 8779
        • 93 Posts
        I’ve created a snippet, but my snippet folder didn’t created in the snippets folder, and I can’t find my snippet PHP files
          • 9130
          • 171 Posts
          Snippets are stored in the database, not in files. If you wish to have them in files you will have to create these files manually.
            • 8779
            • 93 Posts
            Oh I see. Thanks for the info.
              • 8779
              • 93 Posts
              sorry to ask again.
              I’ve created this file manually, then how I call this files in template? since I didn’t create the snippet tag, that can be called in the template.
                • 9130
                • 171 Posts
                Create a snippet through the manager and in the snippet simply include the file, like this:
                include_once($modx->config['base_path'].'assets/snippets/yoursnippet/yourcode.inc.php');
                  • 8779
                  • 93 Posts
                  Then what? I’m getting confused here huh
                  I’ve created the snippet manually and with manager now. Two different snippets here.
                    • 9130
                    • 171 Posts
                    There is only one.

                    As far as MODx is concerned there is only one kind of snippet - the database type, the kind that you define through the manager. Files are just files, not snippets. This is a workaround that enables using the file’s contents for your snippet.

                    What you should have is:
                    - A file with the php code inside it.
                    - A snippet with an statement including the file’s contents
                    Now you can use the snippet in MODx just like you would use any other snippet.
                      • 8779
                      • 93 Posts
                      Okay I get it.
                      So, how to call this include file into the my snippet?
                      Because I just wrote

                      require_once('tera_wurfl/tera_wurfl.php');


                      And it can’t be load, the browser can’t get this files. I think because the path is wrong. Am I Right?

                      This discussion is closed to further replies. Keep calm and carry on.