We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25046
    • 194 Posts
    I'm not really sure that the upgrade caused the snippets not to work, I just happened to notice that they didn't work sometime after I upgraded. The snippets did work before the upgrade (in V1.0.06).

    Basically, when the page is loaded with the snippet on it, all I get is a page that says, "Error".

    I am calling the snippet like this: [!SnippetCall!]

    And my snippet code is:

    <?php
    $version = "products"; // "all" includes everything
    // "products" includes only product information

    $style = "2"; // "0" = Use your own Stylesheet
    // "1" = Stylesheet with nav on the left
    // "2" = Stylesheet with nav on the top

    $logo = "us"; // "us" CompanyName Authorized Reseller
    // "eu" CompanyName Authorised Partner
    ?>
    <!-- Do Not Edit the following line -->
    <?php echo file_get_contents("http://micro.companyname.com/www/?v=$version&s=$style&l=$logo&p=" . $_GET["p"]);
    ?>

    Any suggestions as to how to get this snippet to work? Or what could possibly be wrong in that it worked before?

    Thanks!

    • Try getting rid of the HTML comment and the extra set of closing/opening PHP tags. And snippets should not use "echo" statements, they should "return" the output.
        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
        • 25046
        • 194 Posts
        Thanks Susan.

        I tried getting rid of the HTML comment and the extra opening/closing PHP tags. I also deleted all the PHP comments. It still produced the page that says, "Error".

        Unfortunately, I am PHP illiterate and am not sure how to use "return" instead of "echo". I tried simply replacing the words but that didn't work. I take it that there is something more to it than that.
        • <?php
          $version = "products"; // "all" includes everything
          // "products" includes only product information
          
          $style = "2"; // "0" = Use your own Stylesheet
          // "1" = Stylesheet with nav on the left
          // "2" = Stylesheet with nav on the top
          
          $logo = "us"; // "us" CompanyName Authorized Reseller
          // "eu" CompanyName Authorised Partner
          
          $page = file_get_contents("http://micro.companyname.com/www/?v=$version&s=$style&l=$logo&p=" . $_GET["p"]);
          
          return $page;
          ?>

            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
            • 25046
            • 194 Posts
            Thanks again.

            Well, I tried this and I still got the same error page. I tried clearing the cache but still no luck.

            For fun, I tried accessing the web page referenced in the code and the page loads OK (note that I changed the companyname text)

            I'm sure I am still doing something wrong but I am at loss to figure this out. Any other suggestions to try (besides signing up for PHP training)?


              • 25046
              • 194 Posts
              I think the problem might be with my server PHP settings which have turned off the file_get_contents functionality. So, not a ModX problem at all. I'll soon see. . .
              • Yes, that will definitely do it. You may need to switch to using cURL, if that is available on your server. http://php.net/manual/en/book.curl.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
                  • 25046
                  • 194 Posts
                  I'll have to investigate cURL. I found that my server's file_get_contents functionality worked OK on test files.
                  • If that's the case, then your snippet should work.
                      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
                    • Do you get any errors in the MODx error log?

                      You might also want to check your server's PHP error logs, and perhaps your web server's error logs as well.

                        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