[support] Where to add items to the <head> section for all pages?
Jamie Holly
hovercrafter at earthlink.net
Sun Sep 16 16:46:34 UTC 2012
> On Sun, Sep 16, 2012 at 6:24 PM, Jamie Holly <hovercrafter at 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_js
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_js/7#comment-14344
> >
>
> 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.
--
Jamie Holly
http://www.intoxination.net
http://www.hollyit.net
More information about the support
mailing list