We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42184
    • 27 Posts
    I've created a snippet (code below) that works fine when I put the snippet code into the 'Snippet code (php)' field in MODX manager, but doesn't work at all when I attached the code as a static file. My static file is located at 'assets/templates/foobar/snippets/twitter/gettwitterfeed.php'. I've tried clearing the cache.

    /**
     * gettwitterfeed
     *
     * DESCRIPTION
     *
     * This snippet adds a Twitter feed to a page
     *
     * USAGE:
     *
     * <div id="twitter-feed"></div>
     *
     * [[!gettwitterfeed]]
     */
    $modx->regClientHTMLBlock('
    	<script src="assets/templates/ab/js/twitter.js"></script>
    	<script>
    		$(function() {
    			loadLatestTweets(\'foobar\',2);
    		});
    	</script>
    ');
    


    Does anyone know what the problem might be?
      • 3749
      • 24,544 Posts
      If I'm understanding you, you switched the snippet to a static element? Both the path and the source need to to be set correctly. When you do it right, the file's code should show up in the snippet in the Manager.

      One check is to modify the snippet code and save and see if the file changes (or change the file and reload the snippet edit form in the Manager and see if the changes show up).
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        I ran into problems when converting an existing element to static; on save the existing element's code was saved to the file, thus losing the file's original content. So if you want to have the file's content used when converting an existing element, you need to take the extra step of editing the element to replace its code with the file content.
          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
          • 3749
          • 24,544 Posts
          Yes, and when using any static elements, *ALWAYS* have the file content backed up somewhere else (don't ask me how I know).
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 42184
            • 27 Posts
            Thanks for your help. In the end I deleted and recreated the Snippet which fixed the problem.
              • 3749
              • 24,544 Posts
              FYI, if you (or someone else reading this thread) are working on something that might be distributed as an extra, MyComponent will create the static elements/files for you.
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting