We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18399
    • 60 Posts
    I’m trying to include an external file into a webpage, much like a "Server Side Include" (SSI). The value is stored as a file in a template variable.

    The value I have is:

    assets/files/tables/mtel09.htm

    using the following code

    <?php
    $testValues = explode(’,’,$options);
    $path1 = $modx->config[’base_path’];
    $path2 = $testValues[0];
    $path = $path1 . $path2;
    $result = $path;
    return $result;
    ?>

    I can generate:

    /home/xxxxxxxxx/public_html/xxxx/assets/files/tables/mtel09.htm

    on the webpage.

    However trying to use:

    $result = include_once($path);

    This results in a collapse of the page and an error

    PHP error debug
    Error: include_once(/home/xxxxxxxxx/public_html/xxxx/<quickedit:eventHtmlTable />assets/files/tables/mtel09.htm) [function.include-once]: failed to open stream: No such file or directory
    Error type/ Nr.: Warning - 2
    File: /home/xxxxxxxxx/public_html/xxxx/manager/includes/document.parser.class.inc.php(769) : eval()’d code
    Line: 6

    and also any attempt on a variation of
    $result = include_once(assets/files/tables/mtel09.htm);
    or $result = include_once(/home/xxxxxxxxx/public_html/xxxx/assets/files/tables/mtel09.htm);
    or $result = include_once(http://website/xxxx/assets/files/tables/mtel09.htm);

    doesn’t work either

    So I want to know what is going on here. The above method is certainly the way I’d expect things to work.

    Well actually that’s wrong, I’d expect to be able to link to a file value stored in modx without writing a snippet at all.

    I’ve read many threads on similar things but none seem to have an explanation on how to do this.

    The external file will be automatically updated by another program outside of Modx so can’t be a chunk.

    Mark

      • 22303 MODX Staff
      • 10,725 Posts
      That looks like some kind of QuickEdit related problem. Disable the QuickEdit plugin, clear your cache, and the include should work. Also, I would use include rather than include once, unless you are afraid it will get called twice for some reason.
        • 18399
        • 60 Posts
        Quote from: OpenGeek at Jun 12, 2009, 11:43 AM

        That looks like some kind of QuickEdit related problem. Disable the QuickEdit plugin, clear your cache, and the include should work. Also, I would use include rather than include once, unless you are afraid it will get called twice for some reason.

        Thanks!

        OK that worked, which I find a little disturbing to be honest. If I’m logged in then the pages completely don’t work. That can’t be good. Anyone else experienced this issue?

        Also how do I prevent it returning the 1 and presumably 0 that indicates success of failure of this function.
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          You shouldn’t return your include; just have the include on one line, then a final return; on the last line. Having the return include... line is causing the snippet to return the success/failure output of the function, which you don’t want displayed.

          And yes, QuickEdit often causes conflicts.
            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
            • 18399
            • 60 Posts
            Quote from: sottwell at Jun 12, 2009, 01:02 PM

            You shouldn’t return your include; just have the include on one line, then a final return; on the last line. Having the return include... line is causing the snippet to return the success/failure output of the function, which you don’t want displayed.

            And yes, QuickEdit often causes conflicts.

            OK I have

            <?php
            $testValues = explode(’,’,$options);
            $path1 = $modx->config[’base_path’];
            $path2 = $testValues[0];
            $path = $path1 . $path2;
            require($path);
            return;
            ?>

            and that works great.

            Many thanks for your help especially as if you hadn’t pointed out the conflict I’d have gone further away from the correct solution.

              • 18399
              • 60 Posts
              Quote from: MarkTWIC at Jun 12, 2009, 01:38 PM

              Quote from: sottwell at Jun 12, 2009, 01:02 PM

              You shouldn’t return your include; just have the include on one line, then a final return; on the last line. Having the return include... line is causing the snippet to return the success/failure output of the function, which you don’t want displayed.

              And yes, QuickEdit often causes conflicts.




              Actually its not working that great when I used it again. If the above script fails it ends very inegantly. It is still working fine on the page I originally wrote it for.

              The code now is:

              <?php
              $path1 = $modx->config[’base_path’];
              $array = explode(’, ’,$options);

              foreach ($array as $values) {
              $path2 = $values;
              $path = $path1 . $path2;
              include($path);}
              return;
              ?>

              When I call this from one template it works fine.

              When I call it from a chunk from a ditto call either of these faults occur:

              [!displayTable? &options=`[+#eventHtmlTable+]`!]

              PHP error debug
              Error: include(/home/XXXXXXXX/public_html/xxxx/assets/files/tables/chusa09.htm<a hre) [function.include]: failed to open stream: No such file or directory
              Error type/ Nr.: Warning - 2
              File: /home/xxxxxxxx/public_html/xxxx/manager/includes/document.parser.class.inc.php(769) : eval()’d code
              Line: 8

              or

              [!displayTable? &options=`[*#eventHtmlTable*]`!]

              which I don’t think can work

              PHP error debug
              Error: include(/home/xxxxxxxx/public_html/xxxx/) [function.include]: failed to open stream: Success
              Error type/ Nr.: Warning - 2
              File: /home/xxxxxxxxx/public_html/xxxx/manager/includes/document.parser.class.inc.php(769) : eval()’d code
              Line: 8

              I have two questions.

              How can I make the above code fail elegantly.

              Or why is it failing when it should work in the same way it does straight from a template.

              Mark

                • 28042 ☆ A M B ☆
                • 24,524 Posts
                Is there a reason why you have the # modifier in the TV or placeholder tags? Have you tried this without it? That tag is only for TVs to include the QuickEdit edit button.
                  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
                  • 18399
                  • 60 Posts
                  Quote from: sottwell at Jun 12, 2009, 10:05 PM

                  Is there a reason why you have the # modifier in the TV or placeholder tags? Have you tried this without it? That tag is only for TVs to include the QuickEdit edit button.

                  Yes, I probably didn’t make it clear. I tried that second after the proper tag didn’t work. I didn’t realise this was what it was for. Thanks.

                  Mark

                    • 20413
                    • 2,877 Posts
                    See the links for include-file snippet here: http://modxcms.com/forums/index.php/topic,36714.0.html
                      @hawproductions | http://mrhaw.com/

                      Infograph: MODX Advanced Install in 7 steps:
                      http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

                      Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
                      http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
                      • 18399
                      • 60 Posts
                      Quote from: mrhaw at Jun 13, 2009, 01:27 AM

                      See the links for include-file snippet here: http://modxcms.com/forums/index.php/topic,36714.0.html

                      Not sure what I’m looking for there. But you’re right, # gets the program to run again.

                      If there is a problem the program crashes. I know this is more PHP but is there a way of getting the program to die and not display anything if it can’t find the file? At the moment I’m getting

                      Error: include(/home/xxxxxxxx/public_html/xxxx/) [function.include]: failed to open stream: Success
                      Error type/ Nr.: Warning - 2
                      File: /home/xxxxxxxxx/public_html/xxxx/manager/includes/document.parser.class.inc.php(769) : eval()’d code
                      Line: 8

                      if the file I’m trying to include doesn’t exist or no value is passed.

                      Mark