We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9068
    • 1 Posts
    Hi I’m writing a snippet that displays some dynamic content on the home page. The snippet works on other pages, but the require() function causes an error on the home page. The path is absolute so I’m at a loss as to what the problem is. Relative paths fail, paths using $_SERVER variables fail. Any guidance would be helpful.

    Thanks
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      Usually an include or require statement within a Snippet looks like this:
      include_once($_SERVER['DOCUMENT_ROOT'] . "path/to/file.php");


      If I were you, I’d test your server settings by writing a simple php page that prints out $_SERVER[’DOCUMENT_ROOT’] etc and put it in the root of your site, name it test.php, and then navigate to www.yourdomain.com/test.php

      test.php:
      <?php
      print_r($_SERVER);
      ?>


      What does it kick back out?
        • 4041
        • 788 Posts
        Try using MODX_BASE_PATH in your include or require statement:

        ex:
        include MODX_BASE_PATH."assets/snippets/mysnippet/includes/myincludedfile.php";


        I’ve had success using this technique, hopefully it helps smiley
          xforum
          http://frsbuilders.net (under construction) forum for evolution
          • 9207 ☆ A M B ☆
          • 2,475 Posts
          That’s pulling from the database as well, right? That works on multiple servers so long as the directory structure is the same. I’ll have to give that a try. Where is there a list of MODx constants?