0

I'm building a custom theme and I'm attempting to use require_once __DIR__ . '/templates/variables.php' in my footer.php file, to keep from repeating code that contains variable information... I keep getting an error telling me that my variable is undefined.

The strange thing is that when I use require_once __DIR__ . '/../variables.php' in my /pages/content.php file require_once does work and the variables are being defined correctly and I therefore access their data as intended. Any reason as to why this isn't working in directories above the variables.php template directory but are working in directories below it?

Here is my file structure:

my_theme
       |
       |__footer.php
       |
       |__/templates
          |
          |__variables.php
          |
          |__/pages
             |
             |__content.php
6
  • Are you including the file after you try to use the variables set in the file?
    – s_ha_dum
    Jul 10, 2015 at 18:06
  • No, I'm calling it before. It's the first thing I'm calling when the script runs. So its <?php require_once __DIR__ . '/templates/variables.php' /* Other code goes here */ ?>
    – Corey
    Jul 10, 2015 at 18:30
  • Your description makes it seem like the path is wrong. Dump the generated pathes and compare them.
    – s_ha_dum
    Jul 10, 2015 at 18:40
  • I did... thats why I was confused because the path was correct.
    – Corey
    Jul 10, 2015 at 19:45
  • Something has to be different-- a slash, something.
    – s_ha_dum
    Jul 10, 2015 at 19:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.