When we theming Drupal, we always need to get Drupal 7’s default theme full path:

<?php print base_path() . drupal_get_path('theme', 'themename'); ?>

Above code is the standard way to get Drupal 7 default theme directory.

First, we need to know two Drupal 7 API fuctions: base_path() & drupal_get_path();

1. base_path()

Returns the base URL path (i.e., directory) of the Drupal installation.

base_path() adds a “/” to the beginning and end of the returned path if the path is not empty. At the very least, this will return “/”.

Examples:

  • http://example.com returns “/” because the path is empty.
  • http://example.com/drupal/folder returns “/drupal/folder/”.

File

includes/common.inc, line 2843

Common functions that many Drupal modules will need to reference.

Code

function base_path() {
  return $GLOBALS['base_path'];
}

2. drupal_get_path()

Returns the path to a system item (module, theme, etc.).

Parameters

$type: The type of the item (i.e. theme, theme_engine, module, profile).

$name: The name of the item for which the path is requested.

Return value

The path to the requested item or an empty string if the item is not found.

File

includes/common.inc, line 2829

Common functions that many Drupal modules will need to reference.

Code

function drupal_get_path($type, $name) {
  return dirname(drupal_get_filename($type, $name));
}

Now you should understand how to get Drupal 7 default theme’s full path, go ahead with that on your theme.

0 Likes
439 Views

You may also like

Leave A Comment

Please enter your name. Please enter an valid email address. Please enter message.