We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4803
    • 20 Posts
    I was working my way through addon development using the tutorial in the documentation and modifying it to my needs when I ran into something funny using the include snippet in the tutorial. When you use it on a php file it works just fine, but if you make a chunk file to include javascript, it appends a '1' to the file. A little digging revealed this is because of the way include works in php. I rewrote the include snippet to work the original way if I am including a php file, or to simply return the contents of the file if it is not php

    <?php
    
    $isphp = strpos($file,'.php');
    
    if ($isphp !== false) {
    
    //if the file ends in .php we actually want to include the file
    $o = include $file;
    if (file_exists($file)) {
       return $o;
    } else {
       return "File Not Found: $file";
    }
    
    } else {
    
    //if it does not then we just want to return the text of the file
    if (file_exists($file)) {
       return file_get_contents($file);
    } else {
       return "FILE NOT FOUND: $file";
    }
    
    }
    
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Actually with Revo 2.2 you don't need it at all; use "static" elements. http://rtfm.modx.com/display/revolution20/Upgrading+to+2.2.x#Upgradingto2.2.x-StaticElements
        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
        • 813 ☆ A M B ☆
        • 326 Posts
        Very nice! I ran into this same issue the other day. There's also an extra in the repository that eliminates the "1" issue:

        http://modx.com/extras/package/includesnippet