How nice it would be to have the capability to run modified templates without actually modifying them.

Let me explain.
Right now, the template system has a few real drawbacks:
#1 Tracking and re-mod'ing after upgrade a large headache.
#2 Have to modify a template in many styles if you have styles.
#3 Difficult to test a change on a live board.
Using the "Template Hooks" system (described earlier in this thread), you would not actually modify templates to apply a change. No more length comparison of template code. No more revert and reinstall.
The hooks are defined through AdminCP and saved in a separate table. No templates are actually modified. The proper template code is output when pages are built, but no change is made to the installed templates.
I'll recap that discussion with the example I used:
Code:
Problem: For postbit_legacy, only show the avatar
under certain conditions.
AdminCP mockup solution:
Feature Permission Add Hook
Hook type: Template
Template name: postbit_legacy
Styles: all
Userid: 1
Type: before template
Hook template code:
if (your custom test here or a feature permission test here)
{
$show['avatar'] = false;
}
#1 problem solved: installed templates are not actually modified
The key here is that you are not changing the base template. The modified template code is output only when the page is built. (This would require a small mod to the functions cache_templates and fetch_template, without worry of any noticeable performance penalty.)
#2 problem solved: change is only used for a specific testing account.
Notice in this example that I applied permissions. This makes it very easy for an admin to test a change. In this case, the change would be applied only if the running userid is '1'. You could set this to any testing user account.
#3 problem solved: making change to many styles
In this case, the change will be applied under all styles. One could also specify a list of one or more style id's to limit the change. Again, no change to any vB-delivered table actually takes place.
Another Challenge For The System
A limitation with the "Template Hook" system is that the hook can be applied only before and/or after a style. What about changes to template code in the middle of a template?
Here's how that would look. In this case, we want to modify a template so that "Quote message in reply?" is checked by default when using Quick Reply. This request was raised in a
recent thread here at vb.org.
Code:
Problem: Apply a change within showthread_quickreply template
AdminCP mockup solution:
Feature Permission Add Hook
Hook type: Template
Template name: showthread_quickreply
Styles: all
Type: find/replace
Find: tabindex="4" />
Change to: tabindex="4" checked="checked" />
The system would complain if the "Find:" string match was either (a) not found or (b) not a unique match. Also, an AdminCP utility would be provided to check all hooks for these errors after an upgrade.
In this case, the change applies to all styles and there are no permission limitations.
Developing this template hook system would offer the admin more power and, perhaps more importantly, less maintenance work. Sure, after upgrading vB the admin would have to check that the underlying templates did not change incompatibly, but this would be a heckuva lot easier using this system than applying the changes by hand to templates.
There will be cases when applying a hook would not be the right approach, but this proposal would cover the vast majority of simpler changes.
Comments?