[RFC|Merged] Template Events

These requests for comments/change have lead to an implemented feature that has been successfully merged into the 3.1/Ascraeus branch. Everything listed in this forum will be available in phpBB 3.1.
User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: [RFC] Template Events

Post by EXreaction » Fri Aug 24, 2012 12:27 am

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.

Azrhei
Registered User
Posts: 1
Joined: Tue Sep 04, 2012 7:48 pm
Location: Pensacola, Florida
Contact:

Re: [RFC] Template Events

Post by Azrhei » Tue Sep 04, 2012 8:13 pm

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.

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
	}
}
or for more than one template:

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; 
	}
}
I know I'm probably a lunatic and none of this even applies or makes sense so feel free to disregard these ramblings.

User avatar
imkingdavid
Registered User
Posts: 1050
Joined: Thu Jul 30, 2009 12:06 pm

Re: [RFC] Template Events

Post by imkingdavid » Fri Sep 14, 2012 12:09 pm

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.
I do custom MODs. PM for a quote!
View My: MODs | Portfolio
Please do NOT contact for support via PM or email.
Remember, the enemy's gate is down.

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: [RFC] Template Events

Post by EXreaction » Fri Sep 14, 2012 2:12 pm

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.

User avatar
MichaelC
Development Team
Development Team
Posts: 889
Joined: Thu Jan 28, 2010 6:29 pm

Re: [RFC] Template Events

Post by MichaelC » Fri Sep 14, 2012 4:12 pm

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
psoTFX wrote: I went with Olympus because as I said to the teams ... "It's been one hell of a hill to climb"
No unsolicited PMs please except for quotes.

User avatar
imkingdavid
Registered User
Posts: 1050
Joined: Thu Jul 30, 2009 12:06 pm

Re: [RFC] Template Events

Post by imkingdavid » Fri Sep 14, 2012 5:18 pm

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.
No?
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).
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.
A template event that calls another template event? That doesn't exactly overwrite, that just injects.
I do custom MODs. PM for a quote!
View My: MODs | Portfolio
Please do NOT contact for support via PM or email.
Remember, the enemy's gate is down.

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: [RFC] Template Events

Post by EXreaction » Fri Sep 14, 2012 6:28 pm

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.

Oleg
Posts: 1150
Joined: Tue Feb 23, 2010 2:38 am
Contact:

Re: [RFC] Template Events

Post by Oleg » Mon Sep 17, 2012 4:24 am

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.

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: [RFC] Template Events

Post by EXreaction » Wed Oct 10, 2012 4:02 pm

Bump

Oleg
Posts: 1150
Joined: Tue Feb 23, 2010 2:38 am
Contact:

Re: [RFC] Template Events

Post by Oleg » Wed Oct 10, 2012 8:41 pm

Right now the blocker is the failing test case in the PR, per my previous post.

Post Reply