I have been trying various methods to put javascript into my theme. I just want to have some rotating images on the front page. I tried putting the internal js into page-front.tpl.php and I tried putting it all into a block and having it only show up on the front page. I declared the file on my .info file Really nothing works.
THe js I want to use has internal and external js.
So I read reading here: http://drupal.org/node/171213. It says that the theme folder needs a script.js file that is automatically included. Where do I look to find this file. I can't find it anywhere in any of my directories. I was thinking that maybe the js isn't working becuase of this issue.
Honestly, I've been reading so many posts on js in drupal I'm really confused now, as to what to do.
Any help is totally appreciated.
Becky
Comments
do you try drupal_add_js() ?
do you try
drupal_add_js()?Yes I did. I found a post
Yes I did. I found a post where it said to put the drupal_add_js into a block or on a page.tpl I want it in, but it did not work. I am beginning to wonder if there is something faulty with my installation....Is that possible?
Becky
If you have a custom theme,
If you have a custom theme, you should be able to create a script.js file and upload it to your theme directory (/sites/all/themes/mytheme/script.js). Can you let us know what theme you're using?
Sure. I made a subtheme of
Sure. I made a subtheme of the zen template. So, my next question is, does it have to be called script.js? It's not a big deal to change the file name by any means but is that a drupal standard?
Hi, I think you have 2
Hi,
I think you have 2 options available to you.
This is documented here - http://drupal.org/node/171205#scripts - but the example on this book page is bad because the javascript file in the example is 'script.js' which would actually be included automatically (as per 1. above)
One thing you will have to do is empty your theme registry (see 'The theme registry' at the bottom of http://drupal.org/node/173880) every time you make one of these changes, and I recommend the devel module to help you with this http://drupal.org/node/270064.
Hope this helps.
Baronmunchowsen, when I made
Baronmunchowsen, when I made the file called script.js and added scripts [] =script.js to my .info file, i go the following error message in my admin panel:
warning: file_get_contents(sites/all/themes/custom/wimax_forum/script.js) [function.file-get-contents]: failed to open stream: Permission denied in /Applications/xampp/xamppfiles/htdocs/drupal6/includes/locale.inc on line 1622.
One or more problems were detected with your Drupal installation. Check the status report for more information.
Becky
Status Report relevant?
Does this display when you've not got the scripts[] line in your info file? What are the errors/issues on your status report? This still seems to me to be a path issue as the php function 'file_get_contents' is being passed a path that can't be found (sites/all/themes/custom/wimax_forum/script.js). How is your server configured?
worked perfectly
this is sounds advice,
i wanted to include a 3rd party javascript and css combo, i just added them as directed and it works a treat
i tried before by putting the code into page.tpl.php and the lines i had put in were being automatically deleted, as were the files so i was depending on chmod to protect the files from deletion like a crazy fool
cheers baronmunchowsen
You've probably already thought of this...
I couldn't put the AdSense javascript snippet in a block on D6 until I went to Site configuration >> Input formats >> Add input format, and then have no filters on the new format. Then choose that completely open format when adding your js into the block you create for your js. Just a thought.
Drupalot.com - ask & answer Drupal questions
what is the name of the
what is the name of the input format to add?
Also, thanks for all these suggestions guys, I really appreciate it. I will try them asap.
Becky
Input format
Site Configuation >> Input Formats >> Add Input Format >> ... once you're here, give your input format a name, such as "Javascript," choose "administrator" under "Roles" and don't choose any filters. Then click "Save configuration." You now have a js-friendly option when you're posting/creating any content, block, etc, as an admin. Just remember that when you do need to use javascript, that you click "input format" below the new post or content and choose "Javascript" from the options.
Let me know if I glossed over anything. Hope that helps.
Drupalot.com - ask & answer Drupal questions
I did what you guys
I did what you guys suggested and made an input format for the js and then i declared the external code in my info file. I think the internal javascript is having a problem grabbing the images from my directory. I am posting my code below to see if you guys have any further suggestions.
To be clear, this is what I put in my block