views:

7693

answers:

4

The drupal api has drupal_get_path($type, $name) which will give the path of any particular theme or module. What if I want the path of the current theme?

+10  A: 

this should work (doc):

global $theme;
$path = drupal_get_path('theme', $theme);

// there's also a $theme_path global

global $theme_path;
Owen
Hi Owen Thanks for the info
Kamal Challa
It's better to use `path_to_theme()`, than to use `$theme_path`.
kiamlaluno
A: 

In Drupal 5, you can simply use: path_to_theme()

This will give you a complete path from the root of Drupal to the specific theme directory. Be aware, it does not include a trailing slash.

In Drupal 6, this behaves just a bit differently. If you call it from within your pages, it will call whatever is currently doing the theming... whether that is your theme, a module, etc. Here's the key quote from the API docs:

It can point to the active theme or the module handling a themed implementation. For example, when invoked within the scope of a theming call it will depend on where the theming function is handled. If implemented from a module, it will point to the module. If implemented from the active theme, it will point to the active theme. When called outside the scope of a theming call, it will always point to the active theme.

Source: http://api.drupal.org/api/function/path_to_theme

CaseySoftware
+1  A: 

In D6 path_to_theme() may not behave in a way you expect depending on how you are using it. If you are using it outside any theme preprocess functions, then it will probably give you what you want, but if it is being called within the context of a module's theming/preprocess hook function... it will be pointing to the module path that declared the theme.

Ex. If i have a theme "my_theme" and my module "my_module" which is overriding the forum themes using the preprocess hooks, calling path_to_theme() within my module: e.g. my_module_preprocess_forums()... will return "forums", and not "my_theme" as one might expect.

Very fruity if you ask me.

Fruity functions