I am using this terrific template: http://drupal.org/project/traction
I need to add a Javascript include on all pages. I have grepped about for "DOCTYPE html PUBLIC" but none of the files in ~/sites/all/themes/traction/ contains that text. The only other place that seemed likely was ~/modules/system/html.tpl.php but adding the Javascript include there did not make it appear in the page source. Which file contains the <head> section HTML that is included in all pages?
Thanks!
Hey Dotan,
Find the folder of your them and open the [theme-name].into file Add the line: scripts[] = [path]/[file-name].js Clear the them cache by going to: http://%5Bsite-name%5D/admin/appearance
Done.
This should be done only to your sub theme and not core. If you do an update on your theme later, this will be replace.
OK, I think I have someone so lets see how they do otherwise I'll be back to you.
Thanks
----- Original Message ----- From: Cory Gilliam To: support@drupal.org Sent: Saturday, September 15, 2012 5:24 PM Subject: Re: [support] Where to add items to the <head> section for allpages?
Hey Dotan,
Find the folder of your them and open the [theme-name].into file Add the line: scripts[] = [path]/[file-name].js Clear the them cache by going to: http://%5Bsite-name%5D/admin/appearance
Done.
This should be done only to your sub theme and not core. If you do an update on your theme later, this will be replace.
On Sun, Sep 16, 2012 at 12:24 AM, Cory Gilliam imaaxa@gmail.com wrote:
Hey Dotan,
Find the folder of your them and open the [theme-name].into file Add the line: scripts[] = [path]/[file-name].js Clear the them cache by going to: http://%5Bsite-name%5D/admin/appearance
Done.
This should be done only to your sub theme and not core. If you do an update on your theme later, this will be replace.
Great, thanks. Done!
In addition to the .js files, there is one bit of Javascript that I would prefer to actually appear in the page itself. How should I add it, other than hacking the HTML template file?
On 9/15/12 5:08 PM, Dotan Cohen wrote:
I am using this terrific template: http://drupal.org/project/traction
I need to add a Javascript include on all pages. I have grepped about for "DOCTYPE html PUBLIC" but none of the files in ~/sites/all/themes/traction/ contains that text. The only other place that seemed likely was ~/modules/system/html.tpl.php but adding the Javascript include there did not make it appear in the page source. Which file contains the <head> section HTML that is included in all pages?
Thanks!
modules/system/html.tpl.php puts out the outer most html for the page (actually, this is where the page is finally rendered, with most of the page in variables that it prints.
THIS IS CORE, DO NOT HACK IT.
It is possible that your hacking of it did not work because someone has overridden it (search for other html.tpl.php files)
This template (and any overrides if it is allowed to be overridden) is supposed to get the html tags to include scripts from the $scripts global, which it will print out. A theme is supposed to add needed scripts with a statement in its .info file like: scripts[] = foo.js
Note also that you will need to clear caches after making changes or they may not appear.
A quick google search find http://drupal.org/node/1073212 which has a discussion of a similar issue.
OK, I think I have someone so lets see how they do otherwise I'll be back to you.
Thanks
----- Original Message ----- From: Richard Damon To: support@drupal.org Sent: Saturday, September 15, 2012 5:33 PM Subject: Re: [support] Where to add items to the <head> section for allpages?
On 9/15/12 5:08 PM, Dotan Cohen wrote:
I am using this terrific template: http://drupal.org/project/traction
I need to add a Javascript include on all pages. I have grepped about for "DOCTYPE html PUBLIC" but none of the files in ~/sites/all/themes/traction/ contains that text. The only other place that seemed likely was ~/modules/system/html.tpl.php but adding the Javascript include there did not make it appear in the page source. Which file contains the <head> section HTML that is included in all pages?
Thanks!
modules/system/html.tpl.php puts out the outer most html for the page (actually, this is where the page is finally rendered, with most of the page in variables that it prints.
THIS IS CORE, DO NOT HACK IT.
It is possible that your hacking of it did not work because someone has overridden it (search for other html.tpl.php files)
This template (and any overrides if it is allowed to be overridden) is supposed to get the html tags to include scripts from the $scripts global, which it will print out. A theme is supposed to add needed scripts with a statement in its .info file like: scripts[] = foo.js
Note also that you will need to clear caches after making changes or they may not appear.
A quick google search find http://drupal.org/node/1073212 which has a discussion of a similar issue.
On Sun, Sep 16, 2012 at 12:33 AM, Richard Damon Richard@damon-family.org wrote:
modules/system/html.tpl.php puts out the outer most html for the page (actually, this is where the page is finally rendered, with most of the page in variables that it prints.
THIS IS CORE, DO NOT HACK IT.
It is possible that your hacking of it did not work because someone has overridden it (search for other html.tpl.php files)
This template (and any overrides if it is allowed to be overridden) is supposed to get the html tags to include scripts from the $scripts global, which it will print out. A theme is supposed to add needed scripts with a statement in its .info file like: scripts[] = foo.js
Note also that you will need to clear caches after making changes or they may not appear.
A quick google search find http://drupal.org/node/1073212 which has a discussion of a similar issue.
Thanks. I suspect that my attempt at hacking the core did not show due to the fact that I did not clear the caches - I didn't even know that they exist!
What keywords did you google on to find that page? At the time of the original post, I did google but I did not find anything relevant, frustratingly, as I probably did not know which keywords to google for.
On 9/16/12 6:20 AM, Dotan Cohen wrote:
On Sun, Sep 16, 2012 at 12:33 AM, Richard Damon Richard@damon-family.org wrote:
modules/system/html.tpl.php puts out the outer most html for the page (actually, this is where the page is finally rendered, with most of the page in variables that it prints.
THIS IS CORE, DO NOT HACK IT.
It is possible that your hacking of it did not work because someone has overridden it (search for other html.tpl.php files)
This template (and any overrides if it is allowed to be overridden) is supposed to get the html tags to include scripts from the $scripts global, which it will print out. A theme is supposed to add needed scripts with a statement in its .info file like: scripts[] = foo.js
Note also that you will need to clear caches after making changes or they may not appear.
A quick google search find http://drupal.org/node/1073212 which has a discussion of a similar issue.
Thanks. I suspect that my attempt at hacking the core did not show due to the fact that I did not clear the caches - I didn't even know that they exist!
What keywords did you google on to find that page? At the time of the original post, I did google but I did not find anything relevant, frustratingly, as I probably did not know which keywords to google for.
I believe it was just: Drupal $scripts
OK, I think I have someone so lets see how they do otherwise I'll be back to you.
Thanks
----- Original Message ----- From: Dotan Cohen To: support@drupal.org Sent: Saturday, September 15, 2012 5:08 PM Subject: [support] Where to add items to the <head> section for all pages?
I am using this terrific template: http://drupal.org/project/traction
I need to add a Javascript include on all pages. I have grepped about for "DOCTYPE html PUBLIC" but none of the files in ~/sites/all/themes/traction/ contains that text. The only other place that seemed likely was ~/modules/system/html.tpl.php but adding the Javascript include there did not make it appear in the page source. Which file contains the <head> section HTML that is included in all pages?
Thanks!
The best solution is to include it in the (sub)theme's .info file. Next best is to include it in the .info file of a custom module, if you have one. If nothing else works, there is hook_init(). Never, ever, hack core.
Nancy
Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.
From: Dotan Cohen
I need to add a Javascript include on all pages. I have grepped about for "DOCTYPE html PUBLIC" but none of the files in ~/sites/all/themes/traction/ contains that text. The only other place that seemed likely was ~/modules/system/html.tpl.php but adding the Javascript include there did not make it appear in the page source. Which file contains the <head> section HTML that is included in all pages?
On Sun, Sep 16, 2012 at 2:39 AM, Ms. Nancy Wichmann nan_wich@bellsouth.net wrote:
The best solution is to include it in the (sub)theme's .info file. Next best is to include it in the .info file of a custom module, if you have one. If nothing else works, there is hook_init(). Never, ever, hack core.
Thank you, I will remember that!
A few things here:
- Theme's can override any tpl.php file. You simple copy the tpl.php file to your theme's directory and clear Drupal's cache and you're ready to change that file. This isn't "hacking core", but rather the power of Drupal's templating layer.
- No need for a custom module just to add javascript. The Drupal way in D7 for theme's to add javascript is using the .info file, so long as that file is to be included on every page rendered by the theme. If you need something more conditional, then you can use drupal_add_js inside mytheme_preprocess_page(). Check out the comments here:
http://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_j...
- You can also use drupal_add_js() to add inline javascript. Check the documentation on the link above. You would want the 'inline' type of adding in the code.
- Whenever you add a theme override function or change the theme's .info file, you must clear Drupal's cache for the changes to be noticed by Drupal.
Jamie Holly http://www.intoxination.net http://www.hollyit.net
On 9/16/2012 6:21 AM, Dotan Cohen wrote:
On Sun, Sep 16, 2012 at 2:39 AM, Ms. Nancy Wichmann nan_wich@bellsouth.net wrote:
The best solution is to include it in the (sub)theme's .info file. Next best is to include it in the .info file of a custom module, if you have one. If nothing else works, there is hook_init(). Never, ever, hack core.
Thank you, I will remember that!
On Sun, Sep 16, 2012 at 6:24 PM, Jamie Holly hovercrafter@earthlink.net wrote:
A few things here:
- Theme's can override any tpl.php file. You simple copy the tpl.php
file to your theme's directory and clear Drupal's cache and you're ready to change that file. This isn't "hacking core", but rather the power of Drupal's templating layer.
The problem is that this theme's tpl file does not include the <head> section.
- No need for a custom module just to add javascript. The Drupal way in
D7 for theme's to add javascript is using the .info file, so long as that file is to be included on every page rendered by the theme.
That will only let one include JS files in the theme's directory. I need to include both files on another server, and also inline javascript in the head section.
If you need something more conditional, then you can use drupal_add_js inside mytheme_preprocess_page(). Check out the comments here:
http://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_j...
That does look like a solution, but where to put the call to the function? I it supposed to be in the tpl.php file? I stress that this theme's tpl.php file does not have a <head> section.
- You can also use drupal_add_js() to add inline javascript. Check the
documentation on the link above. You would want the 'inline' type of adding in the code.
- Whenever you add a theme override function or change the theme's .info
file, you must clear Drupal's cache for the changes to be noticed by Drupal.
Noted, thanks!
On Sun, Sep 16, 2012 at 6:24 PM, Jamie Holly hovercrafter@earthlink.net wrote:
A few things here:
- Theme's can override any tpl.php file. You simple copy the tpl.php
file to your theme's directory and clear Drupal's cache and you're ready to change that file. This isn't "hacking core", but rather the power of Drupal's templating layer.
The problem is that this theme's tpl file does not include the <head> section.
You copy the html.tpl.php from the modules/system directory into your theme's directory then clear your cache. Now you can edit the html.tpl.php file in your theme's directory to make any changes you want. I suggest reading the theming-guide, particularly the sections on "core templates and suggestions" as well as "overriding themeable output".
http://drupal.org/theme-guide/6-7
- No need for a custom module just to add javascript. The Drupal way in
D7 for theme's to add javascript is using the .info file, so long as that file is to be included on every page rendered by the theme.
That will only let one include JS files in the theme's directory. I need to include both files on another server, and also inline javascript in the head section.
Documentation is your friend! Please refer to the link I supplied earlier:
http://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_j...
In the very first example blocks are examples of how to add external javascript as well as inline in the head.
If you need something more conditional, then you can use drupal_add_js inside mytheme_preprocess_page(). Check out the comments here:
http://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_j...
That does look like a solution, but where to put the call to the function? I it supposed to be in the tpl.php file? I stress that this theme's tpl.php file does not have a <head> section.
you create a template.php file inside your theme's directory. Inside of that you create a MYTHEMENAME_preprocess_function, changing MYTHEMENAME to the name of your theme (same as the name of your .info file without the .info). Just follow the example in that comment and you'll be fine.