[themes] How to include and use jquery plugin in my theme

Larry Garfield larry at garfieldtech.com
Sun Aug 24 19:07:04 UTC 2008


On Sunday 24 August 2008 2:04:04 pm Sergei Stryukov wrote:
> Hello Larry,
>
> Sunday, August 24, 2008, 9:05:34 PM, you wrote:
> > On Sunday 24 August 2008 9:28:25 am Sergei Stryukov wrote:
> >> Hello Konstantin,
> >>
> >> You can include this script in page.tpl.php:
> >>
> >> <script type="text/javascript"
> >> src="path-tp-theme/scripts/jquery.corner.js"></script>
> >>
> >> Add this code before </head> tag.
> >
> > No, don't do that.  That skips all of Drupal's JS handling and
> > compression and caching mechanisms, and is totally not portable across
> > different sites.  Hard coded paths are never correct.
>
> <script type="text/javascript" src="<?php echo path_to_theme();
> ?>/scripts/jquery.corner.js"></script>
>
> Do you mean that this hard coded path is not correct? I don't think
> so.
>
> Yes, maybe drupal_add_js is better, but this hard coded path is
> correct.

That's not what you posted above. :-)  If you have to reference a file in the 
template directly, yes, use path_to_theme() to avoid hard coding the path.  
However, as Farsheed pointed out even that is insufficient because it won't 
trip Drupal's JS routines and you therefore may not have jQuery itself 
available to you.  That makes the jQuery plugin rather useless. :-)

-- 
Larry Garfield
larry at garfieldtech.com


More information about the themes mailing list