Pages

Thursday 16 August 2012

Include CSS or Javascript file for specific node in Drupal 6

you need to do is add a node preprocess function that adds those files for you. You can do this either in a module or in a custom theme. For a module this would be:


function mymodule_preprocess_node(&$variables) {
$node = $variables['node'];
if (!empty($node) && $node->nid == $the_specific_node_id) {
drupal_add_js(drupal_get_path('module', 'mymodule') . "/file.js", "module");
drupal_add_css(drupal_get_path('module', 'mymodule') . "/file.css", "module");
}
}

or for a theme:
 
function mytheme_preprocess_node(&$variables) {
$node = $variables['node'];
if (!empty($node) && $node->nid == $the_specific_node_id) {
drupal_add_js(path_to_theme() . "/file.js", "theme");
drupal_add_css(path_to_theme(). "/file.css", "theme");
}
}
 
 when you want to insert inline code into something other than technically a node so there's no node id and no PHP input option available.

No comments:

Post a Comment