Themes can exist in many places in the file system. I'm trying to build a function that returnes the full path to the default theme no matter where it is located. The following code works, but it's not too flexible as it only deals with two locations. Is there a standard Drupal way to get the full path to the current default theme? Variables such as $theme_path don't seem to do the trick, as they are all relative and often point to a module instead of the theme.
$default_theme = variable_get('theme_default', null);
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= '/sites/all/themes/';
$path .= variable_get('theme_default', null);
if (! is_dir($path)){
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= '/themes/';
$path .= variable_get('theme_default', NULL);
}
return $path;
Comments
path_to_theme()
path_to_theme() ...
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
I tried that, but
I tried that, but path_to_theme() returns modules/system, which is not a full path and is not even part of the path to the theme. Sure seems like that should work judging by the name.
Could this be a configuration problem? I'm using D6.6.
Yes there have been issues
Yes there have been issues with path_to_theme() not always working properly, in your case returning the path to system.module. I thought these had been fixed but it would seem not!
[update] Looks like current behaviour is by design: see the docs for http://api.drupal.org/api/function/path_to_theme/6. Your approach looks like the right way of getting the path to the default site theme in all circumstances.
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
Solved
It turns out, path_to_theme() works correctly when used within a theme's template.php file, but when used within a module it returns, system/module. Seems kinda like a bug, but maybe there's a good reason.
Anyway, in digging through common.inc, I came up with the following, which is exactly what I needed:
For more info: http://api.drupal.org/api/function/drupal_get_path/6