preprocessor - Include CSS or Javascript file for specific node in Drupal 6 -
what best method including css or javascript file specific node in drupal 6.
i want create page on site has little javascript application running, css , javascript specific page , not want included in other page loads @ all.
i'd advise against using hook_nodeapi
that. adding css , javascript related layout hook_nodeapi
not place it: use themeing. way, can override files when you're going develop new theme. doing nodeapi approach bit harder (you'd have search js/css list files, remove them , replace them own).
anyway: need add node preprocess function adds files you. can either in module or in custom theme. module 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 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"); } }
don't forget clear cache, first.
these functions called before node themed. specifing js/css there allows cascaded approach: can have generic/basic stuff in module , provide enhanced or specific functionality in theme.
Comments
Post a Comment