1

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_path('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?

2 Answers 2

1

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`

Sign up to request clarification or add additional context in comments.

Comments

0

Try to add your javascript code via the hook_form_alter

1 Comment

Could you give an example of what you mean? Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.