We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39438
    • 15 Posts
    I'm running MODX Revolution 2.2.6-pl (traditional) on the MODX Cloud.

    I was reading the official documentation:

    "As of 2.2.0, you can simply add a "static" Snippet: just reference the static file."

    So I tried. I have a PHP script with the file extension *.php. (for now it doesn't matter what it is for). I created under Files within the MODX Manage a new directory (Create Directory) where I wanted to upload my PHP file. Attempting this I was told "php file extension is not permitted" and the upload didn't happen.

    Given that a snippet is raw PHP-code,
    how can I use a static snippet?
    And how do I get into the file system?
    How do I have to name it? (file extension?)
    Is there any place in the documentation where I find which file extension are permitted and which aren't?
    Can anybody tell me more about static snippets use?

    Thanks so much in advance
    kdmeloper

    This question has been answered by multiple community members. See the first response.

    • discuss.answer
      you can set what file types (allowed extensions) in you system settings. Filter by "upload_files". it is a comma separated list of allowed extensions for the assets/files directory.

      Static Snippets are great if you are writing/editing your snippets (or chunks) in an IDE (like PHPStorm). They allow for better syntax highlighting and debugging.

      I have used two ways of creating static snippets:

      1. create the file on my local drive, then upload it via FTP to the MODX directory I want. In the Manager, create a new snippet, check the "static resource" box and then use the browse field to the file I uploaded.
      2. The other way is to create a new snippet, select the "static resource" box, then type in the path and file name you want. MODX will create the file and any directories you enter that don't exists.

      The first way tends to be easier especially if you are working in an IDE.

      As far as extension, it can really have any extension or none at all. For sanity purposes, I use .php for snippets so that my IDE can recognize them, and so I know that they are php snippets.

      Jason
        • 39438
        • 15 Posts
        Hi Jason

        Thank you for your advise. I followed your 1. point and uploaded the snippet (php) via SFTP. And I'll do that in the future.
        I'm still puzzled, though, why the manager's Files/Upload Files function told me that the file extension (php) is not permitted. Never mind.

        kdmeloper
        • discuss.answer
          That extension needs to be added to the file_upload setting in the System Settings (In the Manager.... System menu->System Settings->File System area). MODX doesn't allow uploading a .php extension through its file manager by DEFAULT. You have to add it to the list.

          Jason
          • I would be more inclined to add this as a user setting, unless of course it's a small, well-trusted Manager team. Letting not-fully-trusted editor type users upload .php files could be a problem.
              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
              • 39438
              • 15 Posts
              Hi Jason, cheers for your second important info (Uploadable File Types). It's good to know.

              Sottwell: Can you point me out where in the manager can I find and edit such a user setting. You've got a point here. But I looked under 'User' and 'Security/Manage Users' and I must be blind, can't find an item where I could enter/edit this.

              kdmeloper
              • Edit the user, and create a new upload_files setting for him. You'll probably need to make sure to give him all of the file types you want him to be able to upload; I am pretty sure these are overwritten, not just added to the default.
                  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
                • Excellent recommendation, Susan. Might even could do this as a MediaSource so it could be linked to an Access Group in case of many devs.

                  Jason