Implemented A hook to modify templates just before they are compiled

This suggestion has been implemented. Votes are no longer accepted.
PHP callback on style settings, as done on node: Pages?
No, I mean a simple hook, that provides template name + template code and expects back modified template code. This hook should concern all the templates separately disrespecting <xen:include>s, not only pages or forums or threads.

You see, template hooks does not provide you the full power. Sometimes you need to insert or change something inside a template, that was not planned by the software author. And for this you can use such a hook to simply replace() something you need inside the template on-the-fly. You cannot do this on each page display because it will badly impact performance. So, doing it right before compilation of the template allows you to have original template in the dabatase and changed compiled one. If you uninstall addon, all you need to restore forum functionality is to recompile templates. No need to replace something back in them.

Also we will be able to write a Template Modification System addon ourselves, that will provide a declarative way for an addons to introduce template changes they need to the system. This is very convenient (just look at TMS addon for VBullet by Andres. VBulletin also lacked TMS functionality at the core. And some addons utilized TMS addon functionality to perform custom changes to the templates.
 
Can't you do this with extending the Template Datawriter?
He is responsible for adding,editing and deleting the templates;)

You can see this in controlleradmin/template.php
PHP:
	$writer = XenForo_DataWriter::create('XenForo_DataWriter_Template');
		if ($templateId = $this->_input->filterSingle('template_id', XenForo_Input::UINT))
		{
			$writer->setExistingData($templateId);
		}
 
No, we need original templates in DB to remain untouched. And changes should be visible only on compiled copy.

If you will apply changes to DB template, you will have troubles undoing it during addon uninstall.

Check this.
 
I know tms and i know how it works.

Where's the problem to extend the datawriter?
You can leave the original templates untouched and use a other table/field for the changed;)

ATM we have:

template_compiled (where's the compiled template saved)
template (the "source template")

So why not add a new table: template changes, where you manipulate the templates.
Then on compiling, you query the changes, str_replace them, let xenforo compile the new template and save it "normal" into the template_compiled table?;)

I checked this some time ago and IMHO it should work.

I have no time and i'm too lazy for this,..:(
Maybe we could find 2-5 coders for this?:D
 
i've updated my post
so new post, to make the people following this, read it again^^
 
I'd have to check this, but the current problem that might exist has to do with code event listeners not being loaded in the install/upgrade system. This is usually a safety thing - you don't want an upgrade to fail because of an incompatibility - as you're a bit stuck then, but it interferes with events that do some one-off change (like when compiling a template). It's something I'll have to think about.
 
Hm... maybe there is a way to not get into the conflicts you just mentioned. I had a look at it today and Im going to check some routines tomorrow. Maybe one or two hooks at certain places could handle this, it depends on the way a template gets modified.
 
So why not add a new table: template changes, where you manipulate the templates.
Then on compiling, you query the changes, str_replace them, let xenforo compile the new template and save it "normal" into the template_compiled table?;)
The main problem is to correctly apply changes on template compilation. And I would prefer native XenForo way to do this because this touches the very core of the system and can easily break something after upgrade.
 
Top Bottom