When I use this function in my custom module. It return "modules/system". Weird, it must be a bug.

Comments

boaz_r’s picture

Priority: Critical » Normal

Yep, same for me. Exactly (although that it happens on D6.1 in my case). I reverted to using $base_url + "/sites/all/themes..." which is bad practice, but working for now.

Boaz.

DrewMathers’s picture

On Drupal 6.1, I find that path_to_theme() consistently returns the value of the previous theme used. I thought this might be a caching issue, but calling cache_clear_all() immediatly before path_to_theme() made no difference.

[Edit] Please disregard the above comment. It was a result of my logic error. My path_to_theme() works fine.

brainski’s picture

I have the same problem. Also the global variable $directory shows the path to my custom module.

How to find out the path to my theme?

mrfelton’s picture

same here. I'm getting this problem when trying to use path_to_theme() in a node template file used to style stuff output by the views module. I'm trying to use it in /mytheme/contemplate/node-mycontenttype-teaser.tpl.php, but it just outputs /sites/mysite/modules/views, rather than the path to my actual theme directory (which should be /sites/mysite/themes/mytheme)

prosk’s picture

What error? I m experiencing the same problem. Maybe we have the same logic error??

zigmoo’s picture

Version: 6.2 » 6.3

Hey Guys,

Thanks for posting and thus helping me figure out/fix my own problem. My issue came up when I was creating a new theme (I's a total noob at this) based on a pre-existing theme. Essentially, having two files named themeName.info and containing the same content understandably threw Drupal for a loop!
In the case where a theme's .info file seems to occur twice (once in the old theme, and once more in the new copied theme), Drupal is unable to recognize the duplication issue, and so it only appears the the path_to_theme() is malfunctioning, when in fact, it's pointing to the only occurrence of the theme path that it knows about.

So, my solution/fix was to simply remove the duplication issue by completing my new theme, which was accomplished by removing the old themeName.info file and replacing it with a new one, unique to the new theme.

Hope this helps,

moo

kanani’s picture

In Drupal 6.4 setting the $base_url in settings.php solved the problem.

aaron’s picture

bradweikel’s picture

Status: Active » Closed (works as designed)

I concur. While this is not a duplicate of the original issue in #194098: path_to_theme() returns path to module that calls it, the discussion there resulted in a documentation clarification at http://api.drupal.org/api/function/path_to_theme :

"If implemented from a module, it will point to the module. If implemented from the active theme, it will point to the active theme."

This addresses the general issue, and particularly the case mentioned in comment #4.

arielberg’s picture

workaround - drupal_get_path("theme","mythemename");

matteogeco’s picture

More refined workaround:

$theme_default = variable_get('theme_default', '');
 $path_to_theme = drupal_get_path('theme', $theme_default);

;-)