function path_to_theme

You are here

7 theme.inc path_to_theme()
4.6 theme.inc path_to_theme()
4.7 theme.inc path_to_theme()
5 theme.inc path_to_theme()
6 theme.inc path_to_theme()
8 theme.inc path_to_theme()

Returns the path to the current themed element.

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.

4 calls to path_to_theme()
bartik_preprocess_html in themes/bartik/template.php
Add body classes if certain regions have content.
garland_preprocess_html in themes/garland/template.php
Override or insert variables into the html template.
seven_preprocess_html in themes/seven/template.php
Override or insert variables into the html template.
template_preprocess in includes/theme.inc
Adds a default set of helper variables for variable processors and templates.

File

includes/theme.inc, line 1219
The theme system, which controls the output of Drupal.

Code

function path_to_theme() {
  global $theme_path;

  if (!isset($theme_path)) {
    drupal_theme_initialize();
  }

  return $theme_path;
}

Comments

…and not the themed element, use:

<?php
  drupal_get_path
('theme', 'THEME_NAME');
?>

The path returned with path_to_theme() depends on where and when it's called which can be hard to predict. It's usually fine in most cases but if you're getting unpredictable results use drupal_get_path().

I was calling path_to_theme in block--system--main.tpl.php and for some reason it was giving me garland (I was sub-theming garland). drupal_get_path works much better.

To automatically determine the path to the current active theme, you can use:

<?php
drupal_get_path
('theme',$GLOBALS['theme'])
?>

Absolutely the best approach. Seems to work everywhere, even in subtheme with field.tpl.php placed in the base theme.

if you use different theme for the admin area you get that theme instead...

So, is there any way to get the path,or at least,the name of the current frontend theme and not the administration one?

Try this:

$theme_path = drupal_get_path('theme', variable_get('theme_default', NULL));

It should return the path to the default theme. Handy when you have different front-end and back-end themes.

Pete

Works. mishly++

I used HOOK_theme() in my module to provide a tpl. When calling path_to_theme() in said tpl it returned the path to the module, not the enabled theme.

The solution was to use drupal_get_path().

:-)

If you are missing page.tpl.php in your theme, path_to_theme() will return modules/system path instead oh theme path.

when do node_save inside block_view - block_view is executed twice

I'm trying to get statistic for banner in block and it's necessary to save in block.
How to solve the problem ?