سؤال

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?

هل كانت مفيدة؟

المحلول

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top