Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Extension Problem
Further to my needs of altering the header HTML of Vanilla, I set about writing myself an extension to help me. I read the documentation, I understood it. I wrote my code. It didn't work.
As far as I'm aware, the problem lies in something that I'm doing wrong with the
method.
For outputting HTML head content, the class 'Head' in ./controls/Common.Controls.php is used, around line 322.
This class loops through scripts, stylesheets and strings added to the header, and then the function Render() is used to render the page, outputting the HTML header.
Excellent, I thought. I'll just Set a reference (using the above code) so that Vanilla asks for my version of the Head class (which i called ManualHead) and uses my Render() function instead of its own. So I wrote this:
With the class ManualHead being:
Which should, with the SetReference method just write the entire head to 'test'.
This didn't work.
I tried it with $this->Context->Writer->Write("test"); instead. Nope.
So I tried copying the entire Head class to ManualHead. I even changed the
to
I set a class var$Context. I even tried making ManualHead a new object, and a new ContextObject. Nothing worked.
So, after much playing, and getting annoyed...i've decided to ask the forums. Maybe a php whizz can lend a hand (Mark?) as i've tried my best.
Here's the code in the simplest format I think should work:
I'd be most pleased if someone could help me out :-)
Regards,
Martin.
As far as I'm aware, the problem lies in something that I'm doing wrong with the
$Context->ObjectFactory->SetReference("MyNeatClass", "AnotherClass");
method.
For outputting HTML head content, the class 'Head' in ./controls/Common.Controls.php is used, around line 322.
This class loops through scripts, stylesheets and strings added to the header, and then the function Render() is used to render the page, outputting the HTML header.
Excellent, I thought. I'll just Set a reference (using the above code) so that Vanilla asks for my version of the Head class (which i called ManualHead) and uses my Render() function instead of its own. So I wrote this:
$Context->ObjectFactory->SetReference("Head", "ManualHead");
With the class ManualHead being:
class ManualHead extends Head {
function Render(){
$this->Context->Writer->Add("test");
}
}
Which should, with the SetReference method just write the entire head to 'test'.
This didn't work.
I tried it with $this->Context->Writer->Write("test"); instead. Nope.
So I tried copying the entire Head class to ManualHead. I even changed the
function Head(&$Context) {
$this->Context = &$Context;
}
to
function ManualHead(&$Context) {
$this->Context = &$Context;
}
I set a class var$Context. I even tried making ManualHead a new object, and a new ContextObject. Nothing worked.
So, after much playing, and getting annoyed...i've decided to ask the forums. Maybe a php whizz can lend a hand (Mark?) as i've tried my best.
Here's the code in the simplest format I think should work:
class ManualHead extends Head {
function Render(){
$this->Context->Writer->Add("test");
}
}
$Context->ObjectFactory->SetReference("Head", "ManualHead");
I'd be most pleased if someone could help me out :-)
Regards,
Martin.
0
This discussion has been closed.
Comments
$this->Context->Writer->Add("<".chr(63)."xml version=\"1.0\" encoding=\"utf-8\"".chr(63)."> <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en-ca\">
To my knowledge, mark hasn't yet added support to change this yet. However it would be wise in the future for Arabic languages and such.
For adding just a script, you shouldn't be hacking away directly at the header and core files, instead look at this discussion on how to add a header script as an extension.
I'm not not planning on hacking away at the header and core files; i'm writing an extension to do it for me so that it's lifespan extends across upgrades.
I suspect that the order of execution sees the Common.Control.php script being executed after the extensions, which makes my attempt to change the 'Head' class not do anything.
It's just that I thought I would be able to do this...either that or I'm doing something wrong. Perhaps a php whizz could shed some light on this, or perhaps Mark himself?
M.
The AddString method is dandy, but I want to add code outside of the head, before the rest of the Vanilla forum code - so that I can add my own block of 'stuff' - everything which fits in with the rest of the site that I'm making.
If needs be, I'll just hack about with the core files. Is there any reason why the control classes can't be instantiated after the extensions?
M.
You can always just create your own control and add it to the Head_Render event of the page object if you just want to add something *after* the head.
$MyObj = $Context->ObjectFactory->NewContextObject($Context, "MyClass"); $Page->AddControl("Head_Render", $MyObj);
To be honest, I've never even tried it, but theoretically it should be fine.
The only thing you might stumble across is that your control gets added before the head control and therefore is rendered before the head control. If that is the case, the quick fix is to add your control to the next event in the page, which is the Menu_Render event.
If that happens, though - please let me know. I want to make sure that things get executed in the correct order, and I may have to change the page object a bit for the next release to ensure that happens.
sweeney kisses Mark on the forehead, Mafia Stylee.
I had to use the Menu_Render event as you said... M.