1

I am using bootstrap 3.6 sub-theme/cdn, I've added scripts[] = js/custom.js and I can see it in the source code of the page.

But... javascript is not working. I copied some javascript code modules to test and from my custom.js and still does not work.

how I can run my code javascript in my sub?

1
  • 1
    Welcome to Drupal Answers! What do you mean by is not working? Does it output anything? – kiamlaluno Jun 22 '16 at 6:16
0

To put a JavaScript in your theme you must do the following steps:

Assuming that your sub-theme name is example.

  1. Update your example/example.info to have this scripts[] = js/custom.js. That means the custom.js path is example/js/custom.js.
  2. Clear the cache.

Troubleshooting:

If your code in custom.js is not working then there is something wrong. First, check if there is a js error using browser console. Second, check the http response code make sure that there is no permission issue.

Alternative way to add Javascript.

Another way of adding Javascript is by using drupal_add_js. With this API you can control which page the js is going to load.

1
  • But why duplicate the javascript already in the bootstrap base theme? A sub-theme should be able to re-use code from its parent/base. – therobyouknow Sep 24 '18 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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