I'm working on accessibility issues with a group of forty seven themes. Many of the things I need to fix are the same in all themes - for example, adding a summary attribute to the calendar tables generated by the event module. I'd like to use include() at the top of each template.php file to link a file containing those universally-applicable themes. I'm having some trouble with the paths.
Supposing I'm working with these two files:
/usr/local/www/data-dist/themes/universal-overrides.php
/usr/local/www/data-dist/themes/bluemarine/template.php
When I put this code in bluemarine/template.php:
include("../universal-overrides.php");
... generates a "file not found" warning and the functions don't get called. But when I use THIS code:
include("/usr/local/www/data-dist/themes/universal-overrides.php");
... then it works. Why is that? It looks to me as though the include statement is interpreting that relative path as relative to something OTHER than template.php.
I can just specify the absolute path in each template.php file, but it's going to break each time we copy the themes from my developer's sandbox to the production server, which have slightly different directory structures. Can anyone enlighten me as to why the relative path fails and how I can fix it?
Comments
Well... I don't do themes,
Well... I don't do themes, but the standard way in modules is to use;
drupal_get_path('theme', 'your_theme');http://api.drupal.org/api/5/function/drupal_get_path
Pobster
--------------------------------------------
http://www.justgiving.com/paulmaddern
--------------------------------------------
Context is everything
Templates are evaluated in an eval() context.
They are read, parsed and evaluated on the fly from the POV of the running script - which is always index.php - via the phptemplate theme engine. Not include()ed.
This, among other things, protects from some error problems with bad code in bad templates, as that code is somewhat 'sandboxed'. But yes, it makes things tricky for what it seems like you are trying to do.
You don't need absolute paths to get what you want,
include("themes/universal-overrides.php");will work most of the time, and be portable to similar drupal installs. Relative to the 'current script'.As pobster said,
drupal_get_path('theme', 'your_theme');may help. The variable$directoryis also available as shorthand to give the same result in a phptemplate context.include($directory."/../universal-overrides.php");This is handy to know if you are to be referring to theme-specific css or image resources.But I'd go with the root-relative version.
Note that the eval() context also makes a difference to things like file-context globals and other things.
.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/
.dan. is the New Zealand Drupal Developer working on Government Web Standards
Thanks for the feedback;
Thanks for the feedback; after discussing it with the sysadmin, it looks as though I'm going to have to go with absolute paths, since he has the server configured to disallow relative paths in PHP scripts. I wish I'd known that earlier. Still, I appreciate the comments. It never hurts to know more about how the system works. Thanks!