Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'd advise against using <code>hook_nodeapi</code> for that. Adding CSS and Javascript is related to layout so <code>hook_nodeapi</code> is not the place for it: use themeing. This way, you <em>can</em> override those files when you're going to develop a new theme. Doing that with the nodeapi approach would be a bit harder (you'd have to search the js/css list for the files, remove them and replace them with your own).</p> <p>Anyway: what 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:</p> <pre><code>function mymodule_preprocess_node(&amp;$variables) { $node = $variables['node']; if (!empty($node) &amp;&amp; $node-&gt;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"); } } </code></pre> <p>or for a theme:</p> <pre><code>function mytheme_preprocess_node(&amp;$variables) { $node = $variables['node']; if (!empty($node) &amp;&amp; $node-&gt;nid == $the_specific_node_id) { drupal_add_js(path_to_theme() . "/file.js", "theme"); drupal_add_css(path_to_theme(). "/file.css", "theme"); } } </code></pre> <p>Don't forget to clear the cache, first. </p> <p>These functions are called before the node is themed. Specifing the js/css there allows for a cascaded approach: you can have the generic/basic stuff in the module and provide enhanced or specific functionality in the theme.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload