And if you want to put a script in the <head> I just have a piece of
javascript:
// Add something to <head> (good for when using templates etc)
var addToHead = function(type, url) {
var a;
switch(type) {
case 'script':
a = document.createElement('script');
a.setAttribute('src', url);
a.setAttribute('type', 'text/javascript');
a.setAttribute('defer', true);
break;
case 'css':
case 'style':
a = document.createElement('link');
a.setAttribute('href', url);
a.setAttribute('rel', 'stylesheet');
a.setAttribute('type', 'text/css');
break;
}
try {
document.getElementsByTagName('head')[0].appendChild(a);
a = null;
} catch(e) {
setTimeout(function() {
addToHead(type, url);
}, 100);
}
}
You can then call addToHead('script', '/js/foo.js'); from any template.
Works perfectly for me :-) (and yeah I'm sure it could be jquery-fied
but I just haven't done)
Allan
Chris Scott wrote:
> I'm still a newbie to jQuery so until now I've been using standard HTML
> pages to try out new code. Now, I need to integrate some jQuery into a
> site that uses Smarty templates. I'd appreciate any suggestions on how
> people are using jQuery and Smarty.
>
> My main sticking point right now is where/how to put the jQuery code for
> the page. Sticking it in the template file would mean putting the
> script block outside the head which I don't really want. To keep it in
> the PHP file, I think I'd need to set it as a template variable that
> outputs it to the head. This is the way I'm leaning, but I'm not sure
> this is the best way to do it.
>
> Thanks.
>
>
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/