0

What is the syntax for including Javascript from a remote location into a Drupal 7 page using the Code per node module?

I have seen this code drupal_add_js('path/to/somescript.js') at Managing JavaScript in Drupal 7 | Drupal.org, but it seems that is not for use on Drupal 7.

What would be the Drupal 7 equivalent?

1
  • 1
    The linked documentation is the correct documentation for D7 core. You are trying to use a contrib module, so you need to look at the contrib module's documentation. Commented Sep 28, 2017 at 8:18

2 Answers 2

2

Code per node module is intented to use to have a custom JS for each node. The JS code must be placed inline, in the node add / edit form. You have this tutorial to see how it works.

If you want to add the same js to a specific content type you can create a module custom where you invoke preprocess node hook:

function YOUR_MODULE_preprocess_node(&$variables) {
  if ($variables['type'] == 'INSERT_CONTENT_TYPE') {
       drupal_add_js('path/to/somescript.js');
  }
}

You can also do this in a custom theme, there are examples in this answer.

If you want see a module with drupal_add_js examples and a nice documenttion, you can see the module js_example , which is a module inside Examples 7.x.

0

try this just change the link to whatever external library you are trying to import : drupal_add_js('https://cdnjs.cloudflare.com/ajax/libs/ally.js/1.0.1/ally.min.js', array('type' => 'external', 'scope' => 'footer'));

take a look at this : drupal.org/node/905994

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.