Skip to content

Instantly share code, notes, and snippets.

@ndvo
Created July 30, 2020 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ndvo/feaf1a6b398e02203e2f998c3389bfb9 to your computer and use it in GitHub Desktop.
Save ndvo/feaf1a6b398e02203e2f998c3389bfb9 to your computer and use it in GitHub Desktop.
Add a js to a specific page from a module in Drupal
function mymodule_preprocess_page(&$variables) {
if (isset($variables['node']) && $variables['node']->type == 'book') {
// Add js
drupal_add_js(drupal_get_path('module', 'mymodule') . '/mymodule.awesome.js');
$variables['scripts'] = drupal_get_js();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment