[RFC|Merged] Template Events
- EXreaction
- Registered User
- Posts: 1555
- Joined: Sat Sep 10, 2005 2:15 am
Re: [RFC] Template Events
If the template object is not supposed to be handling the inheritance information and is just told what file to compile (the way it sounds, but I haven't looked into the new template system much), then whatever thing is telling the template system to compile it should also tell it what directories to look in for events.
-
- Registered User
- Posts: 1
- Joined: Tue Sep 04, 2012 7:48 pm
- Location: Pensacola, Florida
- Contact:
Re: [RFC] Template Events
I just had to ramble so I'm sorry if this is meaningless or stupid.
Would it be simple to have an event that triggers when a template is about to be processed? This way I could just modify the template in a plugin? such event could be given a list of vars to be used in the template, the name of the template (overall_header) and the data that will be rendered. Then I could just use a find/addbefore or find/addafter function to make changes. perhaps even an event after the the template has been processed.
I would think that this would make changing the template files themselves unneccessary while making it easy to convert some mods (not all, but some) into an extension/plugin.
or for more than one template:
I know I'm probably a lunatic and none of this even applies or makes sense so feel free to disregard these ramblings.
Would it be simple to have an event that triggers when a template is about to be processed? This way I could just modify the template in a plugin? such event could be given a list of vars to be used in the template, the name of the template (overall_header) and the data that will be rendered. Then I could just use a find/addbefore or find/addafter function to make changes. perhaps even an event after the the template has been processed.
I would think that this would make changing the template files themselves unneccessary while making it easy to convert some mods (not all, but some) into an extension/plugin.
Code: Select all
myeventhandler($vars,$tpl_name,$data)
{
// Test for the template I want to modify
if($tpl_name != "overall_header")
{
return; // not the template I want
}
// Add some template variables of my own
$myvars = array('SOME_VAR' => some_value);
$vars = array_merge($vars,$myvars);
// Try a find and addbefore
try
{
$template::find_addbefore($data,"<? code to find ?">,"<? code to add ?>");
}
catch (ERR_FIND_NOTFOUND)
{
// Log error
// Handle it gracefully
}
}
Code: Select all
myeventhandler($var,$tpl_name,$data)
{
switch ($tpl_name)
{
case 'overall_header':
// modify overall_header
break;
case 'overall_footer':
//modify overall_foot
break;
default:
//My mod don't do shtuff here
break;
}
}
- imkingdavid
- Registered User
- Posts: 1050
- Joined: Thu Jul 30, 2009 12:06 pm
Re: [RFC] Template Events
An issue that was brought up in the most recent IRC Discussion meeting was that we need to have a way to allow one extension to overwrite a template event of the same name in another extension, without overwriting all of the other extensions. Currently, if two extensions provide a template file for the same template event, both are used. We would like to retain that functionality but also add the ability for the second extension to overwrite the template event from the first extension.
So, we need to brainstorm the best way to do this.
So, we need to brainstorm the best way to do this.
- EXreaction
- Registered User
- Posts: 1555
- Joined: Sat Sep 10, 2005 2:15 am
Re: [RFC] Template Events
Why would this ever be needed? If an extension wants to let others over-write parts of their code, the extension should have it's own hooks which let other extensions control how it works.
Re: [RFC] Template Events
Just include one after another? This needs to be allowed (one after another) as things like the top right menu will be used by numerous extensions.
Formerly known as Unknown Bliss
No unsolicited PMs please except for quotes.psoTFX wrote: I went with Olympus because as I said to the teams ... "It's been one hell of a hill to climb"
- imkingdavid
- Registered User
- Posts: 1050
- Joined: Thu Jul 30, 2009 12:06 pm
Re: [RFC] Template Events
No?Unknown Bliss wrote:Just include one after another? This needs to be allowed (one after another) as things like the top right menu will be used by numerous extensions.
Including one after the other includes both. We are wanting a way to include only one of the two (i.e. the second overwrites the first).
A template event that calls another template event? That doesn't exactly overwrite, that just injects.EXreaction wrote:Why would this ever be needed? If an extension wants to let others over-write parts of their code, the extension should have it's own hooks which let other extensions control how it works.
- EXreaction
- Registered User
- Posts: 1555
- Joined: Sat Sep 10, 2005 2:15 am
Re: [RFC] Template Events
When would this ever be needed though? Why should one extension completely overwrite one specific section of one specific extension?
This does not sound like something that should be allowed at this high of a level. If the original extension author wanted to allow others to disable or replace certain parts of their extension, they should have hooks in their own php code in the extension that specifically allows others to over-write or control the parts of the extension the author believes are safe to over-write or control.
This does not sound like something that should be allowed at this high of a level. If the original extension author wanted to allow others to disable or replace certain parts of their extension, they should have hooks in their own php code in the extension that specifically allows others to over-write or control the parts of the extension the author believes are safe to over-write or control.
Re: [RFC] Template Events
Please look at the failing test case in the current template events PR. That's something that should work. Fix it any way you want that doesn't break the rest of the test suite. Then if other use cases come up we'll deal with them the same way.
- EXreaction
- Registered User
- Posts: 1555
- Joined: Sat Sep 10, 2005 2:15 am
Re: [RFC] Template Events
Right now the blocker is the failing test case in the PR, per my previous post.