API page: http://api.drupal.org/api/drupal/modules--system--page.tpl.php/7

Describe the problem you have found:

There is a discrepancy between Drupal 6 and Drupal 7 and with the documentation of Drupal 7 with regards to the $directory variable.

In Drupal 6, when you have a theme called for the purpose of this example base_theme with a page.tpl.php and have a link to an image in this form: <img src="<?php print $base_path . $directory; ?>/images/image.jpg" alt="" /> and create a theme that inherits this base_theme and its page.tpl.php, the path returned for the inherited theme is the image folder of the inherited theme which allows for override of the base theme.

However, in Drupal 7 the path returned is that of the base_theme and not the inherited theme.

I personally prefer the Drupal 6 approach and I am wondering if this is a bug in Drupal 7 or if the behavior has changed and was not updated in the documentation?

Thanks!

Comments

aspilicious’s picture

Version: 7.x-dev » 8.x-dev
Issue tags: +Needs documentation

Bugs are fixed first in latest dev release of drupal.
Adding the needs documentation tag so the doc people notice it.

I don't know if it is a bug or not.

jhodgdon’s picture

Version: 8.x-dev » 7.x-dev
Component: token system » theme system
Issue tags: -Needs documentation +Needs documentation updates

Sounds like this is something that needs to be documented in the update guide for D6/7 for theming. Not sure why it was in the token component.

LaurentGoderre’s picture

I wonder why it changed if it worked perfectly well in Drupal 6....

damien tournoud’s picture

Status: Active » Closed (duplicate)
jhodgdon’s picture

Status: Closed (duplicate) » Active

Actually, this isn't a duplicate. This issue is about adding update docs for d6/7 for the $directory variable in page.tpl.php. That other issue is about fixing the doc for the path_to_theme() API function in d7/8. They are related, but not the same issue.

LaurentGoderre’s picture

For simplicity sake though, directory should be a simple as it gets to use....returning the folder of the current theme... I don't think theme developers want to know about the inner logic etc..they just want that path, invariably pointing to the right place regardless of theme nesting or other factors.

Thoughts?

LaurentGoderre’s picture

This code did the job for me:

function THEME_preprocess_page(&$vars){
	global $theme_key;
	$themes = list_themes();
	$theme_object = $themes[$theme_key];

	$vars['directory'] = drupal_get_path('theme', $theme_object->name);
 }
jhodgdon’s picture

If you want to request a change to what is in the $directory variable, please file a different issue against Drupal 8. This issue is currently about documenting the change between drupal 6 and 7.

LaurentGoderre’s picture

Status: Active » Closed (works as designed)

Sorry. It seems that Drupal 6 actually has the same problem so this issue can be closed. It all depends on the file structure etc.

That being said, both the Drupal 6 and 7 documentation need to be changed to outline the unpredictable nature of that variable.