View Full Version : Adding Javascript with a product,
Dunhamzzz
06-18-2009, 10:08 AM
Hey, I'm making a pretty extensible mod for vb, and need to put some JS in the headerinclude template. It needs to be pulled from a database for each page too.
I know its probably well documented somewhere but I just can't search for it as the terms are pretty common. I'm guessing its a hook of some sort?
Dismounted
06-18-2009, 11:02 AM
$headinclude .= '<!-- something -->';
Use it at a hook just after it is fetched (style_fetch, or something similar, check it!).
Dunhamzzz
06-19-2009, 11:00 AM
No joy.
Put the following code at the "style_fetch" hook and nothing was included in the header.
$headinclude.= '<script type="text/javascript" src="clientscript/juice/js/jquery.min.js"></script><script type="text/javascript" src="clientscript/juice/js/jquery.juice.popover.js"></script>';
Not using vboptimize or anything.
Also, could you elaborate on "something similiar"?
Dismounted
06-19-2009, 11:08 AM
Also, could you elaborate on "something similiar"?
Meaning check the hook location - as you found out, I was wrong. Use global_setup_complete.
Dunhamzzz
06-19-2009, 01:28 PM
ok thanks for the quick response + help :)
Another method I cam across used in an existing plugin was a hook at 'global_start' using the code:
$vbulletin->templatecache['headinclude'] .= $js;
Is there any advantage with either method? Speed/resource wise?
Dismounted
06-20-2009, 04:00 AM
It doesn't really matter either way.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.