PDA

View Full Version : Hook to header or headinclude


encryption
05-23-2010, 09:52 PM
Hey guys, hopefully someone can help me here. I have searched all over vbulletin.org, .com, and Google for 3-4 hours now and can't find an answer to what should be a simple question for my first plugin experience!

I want to add some custom data to the headinclude template, and I'd like to do it via a plugin without actually editing the headinclude template. I downloaded the class_bootstrap.php include and see two different hooks: parse_templates, which seems to happen just before header processing, and process_templates_complete, which seems to happen just after processing and before rendering.

I see this code in the class_bootstrap.php include file:

$templater = vB_Template::create('headinclude');
$templater->register('foruminfo', $foruminfo);
$templater->register('pagenumber', $pagenumber);
$templater->register('style', $style);
$templater->register('basepath', VB_URL_BASE_PATH);
$headinclude = $templater->render();


Since $headinclude isn't touched anywhere else through the point of where process_templates_complete is called, I just assume I could add text directly to that variable from my plugin. I have tried all sorts of things to add my line of code, but from what I understand, this should work:

$headinclude = $headinclude . '<script src="djdb/ajax.js"></script>';


This line never appears anywhere in my page source. Can someone please help figure out how to insert this line into the header via a plugin? Or tell me what I'm doing wrong and how I can do a plugin correctly? Thanks!

encryption
06-02-2010, 02:20 AM
anybody? :confused:

DragonBlade
06-02-2010, 07:59 AM
I would create a simple plugin and using hooks in the template:

Hook Location: Parse Templates


$javascript = '<script src="djdb/ajax.js"></script>';

$template_hook['headinclude_javascript'] .= $javascript;

encryption
06-06-2010, 08:42 PM
I don't see a template called headinclude_javascript in the style manager, so can you help me understand what it is? Should it be headinclude instead?

Or, if that is correct, I didn't see a headinclude_javascript hook in the php code. All I saw was the parse_templates hook. Where did the headinclude_javascript come from?

--------------- Added 1275868704 at 1275868704 ---------------

Thank you DragonBlade, I got this to work by using headinclude_javascript. I'm not too sure how I would know that the template hook exists as that name, but it definitely works! Can you help me understand how you chose headinclude_javascript? I need to do another hook into the newthread template, and am equally as lost.

I want to add a new field, so I think it would be at newthread_form_start, but I tried a similar hook to what you suggested for my headinclude but I'm having no luck. Once I get the new field added, I'm going to need to hook into the submit button too so I can process the results when the thread is created. I hate to be dependent on someone every time if I could learn how to do it on my own! Thanks man

DragonBlade
06-09-2010, 10:24 PM
The hooks are within the templates

For example, headinclude_javascript is within headinclude template. And the hook looks like this:
{vb:raw template_hook.headinclude_javascript}

encryption
06-18-2010, 04:06 AM
oooooh. I thought those were calls, not declares. Thanks, this should help!