drupal_get_path

5 common.inc drupal_get_path($type, $name)
6 common.inc drupal_get_path($type, $name)
7 common.inc drupal_get_path($type, $name)
8 common.inc drupal_get_path($type, $name)

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.

169 calls to drupal_get_path()

1 string reference to 'drupal_get_path'

File

includes/common.inc, line 2712
Common functions that many Drupal modules will need to reference.

Code

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

Comments

More information

  • It returns the path without slashes in front or after.
  • That's the type *first*, then the project name
    drupal_get_path('module', 'name_of_module');

    I reverse that enough (and then get confused as to why it isn't working) that i felt it worth documenting here, so the 'doh!' moment of realization comes sooner...

  • The valid types are as listed:
    • module
    • theme
    • profile
    • theme_engine

    I can't think of any others and i can't even think of a reason to use the last one.

link to types

link to all valid types or at least listing them would be nice.

Libraries?

Is there any way to properly get the path to a library?

Example:

<?php
drupal_add_js
(drupal_get_path('library', 'modernizr') . '/js/modernizr-1.6.min.js',
                            array(
'group' => JS_THEME, 'every_page' => TRUE));
?>

libraries module

Yes, there is a way. The function is in the libraries module.
Example:

<?php
drupal_add_js
(libraries_get_path('modernizr') . '/js/modernizr-1.6.min.js', array('group' => JS_THEME, 'every_page' => TRUE));
?>

Can you explain?

What does this parameter of the drupal_add_js function do?
array('group' => JS_THEME, 'every_page' => TRUE)

Simple

Documentation is located here.
http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_ad...

Basically, the group is a weight level, with the javascript entries having their own weight below that particular group, and every_page denotes whether or not the js should be added to every page.

Login or register to post comments