Borja Borja - 2 years ago 100
PHP Question

Add css and js only for other "page--node--x.tpl.php" in Drupal 7?

i would like to have other template for only page (in my case node/348), so i write that i must create other


but now how can add other external css and js file ? where ?

Maybe in template.php ?

Thanks a lot and sorry for my english :)

Answer Source

Make a hook_node_view in one of your custom module, then check the node id is 348 and inject your css and js like this :

function nameOfYourModule_node_view($node, $view_mode, $langcode) {
  if ($node->nid == 348) {
    $node->content['#attached']['js'][] = array
      'type' => 'file',
      'data' => path_to_theme() . '/js/my_script.js',
      'group' => JS_THEME,
      'preprocess' => TRUE,
      'scope' => 'footer',
      'weight' => '999',
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download