Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By PMorris on
I'd like to avoid breaking my theme paths eg. ( /sites/all/themes/currenttheme ) by using a php variable like $directory/currenttheme to get the path for the current theme running. I know I saw this somewhere as recommended practice but I can't seem to figure out the proper syntax to do it.
Can anyone point me to the right page or tell me the syntax for it?
The problem is when I moved my theme from a local test site to remote multiinstallation of drupal, all the theme paths to my image directory broke
Thanks!
Comments
_
See http://api.drupal.org/api/function/drupal_get_path
Thanks!
Brilliant! I was searching all over for it but I kept putting in the wrong search terms I guess. Cheers
_
welcome ;-)
Here's the code I ended up using
In my page-front.tpl.php, here's an example of how I ended up doing my theme's logo so the path doesn't break when I move the theme around:
<img src="/<?php print path_to_theme(); ?>/images/logo.gif" alt="<?php print t('Home') ?>" id="logo" />
You can save yourself a few
You can save yourself a few keypresses and a function call by using this instead:
This will work
drupal_get_path('theme',
drupal_get_path('theme',$GLOBALS['theme'])
Although you can use what Drupal offers and find information about the current theme from the global variables or functions.
global $theme;
global $theme_path;
path_to_theme();
Take care.
Sharif.