XF 1.2 Template Modifications and Comparison

Anyone who has developed add-ons for XenForo 1.1 knows that template hooks are a pain. They're a pain for us too, to say the least. Plenty of people have installed the Template Modification System add-on. We've been planning a TMS-like system for some time, before the XenForo add-on was ever actually released.

XenForo 1.2 will deprecate the template hook system and introduce it's own template modification system to make it easier for add-on developers to change templates. Note that I'm primarily focused on add-on developers here. It is possible to create your own custom template modifications if you're not an add-on developer, but unless you have multiple styles, I'd recommend just making the changes to the templates directly.

Let's look at what a template modification is:

ss-2013-04-12_11-35-58.webp


It's simply a "find this" and "replace with that" style replacement. You can do this to any template. If your find matches multiple times in a single template, it will replace each occurrence.

Applying a template modification does not actually modify the template, so it will not show up as customized and it will be automatically reapplied (if possible) when upgrading.

For those of you that want technical details, the modifications are applied before a template is parsed. If the modifications cause a template compilation error, they are automatically disabled.

Here's what the template modification overview looks like:

ss-2013-04-12_11-41-07.webp


All of the template modifications will be listed here, grouped by add-on and ordered by template. The checkbox enables/disables the modification. Note that if the modification is part of an add-on (and you're not in debug mode), you will not be able to edit the modification here but you can enable/disable it. More about this when editing a template.

The 3 numbers indicate the number of times the modification matched (green), the number of times the modification failed to match (grey) and the number of times the modification caused an error (red).

Editing a Template
There are a few new bits when editing a template as well.

ss-2013-04-12_11-43-10.webp


There are 3 new things here:
  • The "prevent" checkbox. If selected, modifications will be never be applied to this template. This can be used to quickly check a template without modifications or to adjust the modifications manually.
  • The "view template modifications" link. I'll discuss this below.
  • The "view custom changes" link. This will simply display a comparison of the parent version of the template (probably the master version) and the current version so you can identify the differences.
When you select view template modifications, you'll see an overlay like this:
ss-2013-04-12_11-43-25.webp

This shows you a comparison of how the template modifications will be applied to this template.
If you choose to manually apply modifications, the template modifications will be "materialized" into the template - they will actually be written into the template and automatic application of modifications will be disabled in this template. You can then manually edit the modifications if you wish. (Obviously if you upgrade an add-on and they've changed their modifications or you install a new add-on that changes this template, you won't be getting those new modifications so this should be used with care.)

Admin and Email Templates
These aren't left out. Add-on developers will have access to very similar systems that allow the admin and email templates to be manipulated in the same way.
We look forward to more dynamic add-ons with XenForo 1.2. :)
 
Last edited by a moderator:
Isn't each template having a file or a set of files(HTML and CSS) associated with it? That is what I meant.
No, not really. The templates only exist in the database.

Basically, I'd like to know if they are stored in any accessible files?
No.

I've only had a couple of months forum licensing experience, not familiar with all 1.1 features yet. So, I'd like to know if this meant: When editing a template and if you've saved multiple times, if you click the "Revert Template..." button, the very last saved version will be brought back? Can you please correct me if I understand it wrong?
It deletes your customizations.

Really wish the TM would allow exporting modified templates, otherwise it feels very incomplete for the feature.
Well, you can "materialize" the changes by manually applying them and it will give you the modified template which you could then export. But if you're just doing this with your own changes, the template modification system won't provide you with any value - just edit the templates directly.
 
Thanks for your responses, Mike!

No, not really. The templates only exist in the database.

If automatically applied changes to the templates only exist in the database, couldn't it be possible to make them into files written in languages such as XML with the power of transporting and storing data, so that exporting and importing templates/styles modified in the template modification system become feasible?

Well, you can "materialize" the changes by manually applying them and it will give you the modified template which you could then export. But if you're just doing this with your own changes, the template modification system won't provide you with any value - just edit the templates directly.

The existing TMS add-on is used by people who want to do template modifications(their own changes), not just by add-on developers, why can't the feature coming from the core serve that purpose, as well?

Why not make this feature be more useful to MANY, not limited to a few?

Add-on developers are very important part of this community. But the satisfying experience of purchasing an add-on comes from both the quality of the product AND the quality of support. I've seen several great add-on developers in xenforo, who produce excellent add-ons and stand behind their products diligently supporting them. But, unfortunately, not many.

So not everyone can rely heavily on the add-on devs for every bits needed here and there. Plus, basic HTML, CSS, SQL and PHP aren't rocket science, almost anyone could master the basics of those within short period of time(maybe OOP is another story). And that makes most xenforo customers potential coders themselves -at least be able to modify templates related to styling. When you have dozens templates modified directly - even if they are your own changes(not for sale), you would also want to use a template modification system to make upgrading an easier process. Just, providing the export/import functionality, so that the feature feels complete.
 
If I have this right, then this only applies to add-ons... so, how much is this going to clash with custom styles where stylers add or remove default code and replace with their own? The add-on would be making the change at the master, but it can't be passed down because the custom style doesn't have the same code in the style template to swap and replace.
 
Oh I can see so much pain when this is released.

Also PHP callback should just be getting run on the whole thing, sometimes regex doesn't cut it. I'd like to be able to make a callback with an 'in' string and I return an 'out'. Although like you do half the time I guess it would just be a content variable with reference.
 
Oh I can see so much pain when this is released.

Also PHP callback should just be getting run on the whole thing, sometimes regex doesn't cut it. I'd like to be able to make a callback with an 'in' string and I return an 'out'. Although like you do half the time I guess it would just be a content variable with reference.
They are not removing the template hooks right away, so, hacks wouldn't immediately break.
Though it will be a lot of work to move to the new system, especially if you need to do add variables to the Views

Of course, I am not looking forward to the regex over regex competition from add-ons :)
 
They are not removing the template hooks right away, so, hacks wouldn't immediately break.
Though it will be a lot of work to move to the new system, especially if you need to do add variables to the Views

Of course, I am not looking forward to the regex over regex competition from add-ons :)
...and especially that a template can be used in different views if I'm not mistaken (cf the editor).
 
...and especially that a template can be used in different views if I'm not mistaken (cf the editor).
A template could be used in different views, but practically .. there is a 1-1 template-view mapping. I am more concerned with classes that do not actually provide a view but use the default Xenforo_ViewPublic, since in that case, the controller itself would need to be overridden
 
If I have this right, then this only applies to add-ons... so, how much is this going to clash with custom styles where stylers add or remove default code and replace with their own? The add-on would be making the change at the master, but it can't be passed down because the custom style doesn't have the same code in the style template to swap and replace.
It does it per style. The numbers on the list tell you:
*green: how many times successfully applied
* gray: how many times unsuccessfully applied
* red: how many times it caused compilation error.
Oh I can see so much pain when this is released.

Also PHP callback should just be getting run on the whole thing, sometimes regex doesn't cut it. I'd like to be able to make a callback with an 'in' string and I return an 'out'. Although like you do half the time I guess it would just be a content variable with reference.
The RegEx Mike showed fetches the whole template.
 
It does it per style. The numbers on the list tell you:
*green: how many times successfully applied
* gray: how many times unsuccessfully applied
* red: how many times it caused compilation error.
Which means add-ons suddenly don't work per style versus add-ons working regardless of style presently, due to hooks.

I asked because of how the TMS addon works, exactly as you outlined. This means an admin then has to adjust an add-ons template modification per style, in order to get them working correctly.

This is one issue we don't have now with Xenforo... not sure if this is a move forward or backwards.
 
Which means add-ons suddenly don't work per style versus add-ons working regardless of style presently, due to hooks.

I asked because of how the TMS addon works, exactly as you outlined. This means an admin then has to adjust an add-ons template modification per style, in order to get them working correctly.

This is one issue we don't have now with Xenforo... not sure if this is a move forward or backwards.
Unless add-ons are overly specific, I can't see this being too much of an issue. If the comments for template hooks are left in, it'll provide a non-stylistic anchor for these modifications to attach onto.
 
The existing TMS add-on is used by people who want to do template modifications(their own changes), not justby makes most xenforo customers potential coders themselves -at least be able to modify templates related to styling. When you have dozens templates modified directly - even if they are your own changes(not for sale), you would also want to use a template modification system to make upgrading an easier process. Just, providing the export/import functionality, so that the feature feels complete.

!important;
 
+1 :coffee:

View attachment 44509


^ If I can't do this without entering developer mode or making an add-on.... XenForo's TMS will be a waste of space and resource.

More so it will conflict with the current established standard.
Do what? Create one? It may be targeted at add-ons, but I can only assume it is visible to the administrator without debug mode since it provides insight into if it was successful or not.
 
Top Bottom