We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    The include function returns 1 for success and 0 for failure. If you return the return value of an include statement, you’ll get the 1 (or the 0 if it fails). You just want the include function to do its thing, not display a return value.
    <?php
    if (!file_exists($file)) return '';  
    include $file;  
    return;
    ?>
    


    See http://sottwell.com/working-snippets.html

      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
      • 1169
      • 312 Posts
      Thanks Susan & Bob

      Then the docs at http://rtfm.modx.com/display/revolution20/Managing+Resources+and+Elements+via+SVN

      Need to be updated.

      I think this just goes to show how many MODx’ers use storing templetes, snippets, TV’s and chunks in files instead of the usual database.

      This was last edited in Dec 2009.

      Or maybe those who know what they are doing and are working on big projects are using this method.

      Would this be the same for Templates, Snippets, Tv’s and Chunks?
        DEVELOPMENT ENV:- Ubuntu 12.04 | MODx Revolution 2.2.8 | LAMP 2i Apache 2.2.22 | Php 5.3.10 | Mysql 5.5.31 MySQL client version: 5.5.31
        • 27708 MODX Staff
        • 2,502 Posts
        Allan, I’ll test it out and update the docs to reflect the variation suggested by Susan. Even though most of Revo was done in 2009 a tonne has changed too. Thanks for being persistent and sharing.


        Jay
          Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
          • 3749
          • 24,544 Posts
          Quote from: sottwell at Sep 30, 2010, 07:11 AM

          The include function returns 1 for success and 0 for failure. If you return the return value of an include statement, you’ll get the 1 (or the 0 if it fails). You just want the include function to do its thing, not display a return value.
          <?php
          if (!file_exists($file)) return '';  
          include $file;  
          return;
          ?>
          


          Susan, That’s only true if the "included" file has no return statement. if the included file has a return statement,

          return include $modx->getOption('assets_path') . 'file.php';


          will return that value rather than 0 or 1.

          IOW, if file.php contains

          return "Hello there.";


          the snippet tag will be replaced with "Hello there." (At least in Revo -- I assume it would be the same in Evo).

          That means that for any "return included" file that contains

          return ’’;

          There won’t be any output where the tag is.
            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
            Interesting... I didn’t know that; although in the case of chunks and templates there would most likely be no return statement in the included file.

            http://www.php.net/manual/en/function.include.php

              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
              • 1169
              • 312 Posts
              Am I reading this rite.

              A chunk can only have HTML + placeholders + scripts and therefore cannot have a return statement.

              A template can have PHP code therefore it could end with a return statement.

              What about a TV?
                DEVELOPMENT ENV:- Ubuntu 12.04 | MODx Revolution 2.2.8 | LAMP 2i Apache 2.2.22 | Php 5.3.10 | Mysql 5.5.31 MySQL client version: 5.5.31
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                A TV using @EVAL behaves much like a snippet; the code following the @EVAL is run through the PHP eval() function. Otherwise, it’s just HTML, like a chunk.

                  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
                  • 1169
                  • 312 Posts
                  Thank you again Susan.
                    DEVELOPMENT ENV:- Ubuntu 12.04 | MODx Revolution 2.2.8 | LAMP 2i Apache 2.2.22 | Php 5.3.10 | Mysql 5.5.31 MySQL client version: 5.5.31