Drupal 6 - Add Javascript to a single page
When I need to add Java Script to a single Drupal page, I paste the following in my node.tpl.php file:
<?php drupal_add_js(drupal_get_pat开发者_JAVA技巧h('theme', 'INSERT_NAME_OF_THEME') . '/INSERT_NAME_OF_JS_FILE.js'); ?>
It works fine, but I have been told it is not best practice. What would be best practice?
in your phptemplate page, in a preprocess function u should like this:
function controller_preprocess_page(&$vars){ if($vars['node']->nid == "THE_ID_OF_THE_NODE")
$vars['varjs'] = 'js/yourjs.js'; }
and then in your page u can do " ...srcipt`
Try to add your javascript code via the hook_form_alter
精彩评论