XF 1.2 How to replace all the contents in a template using Template Modification

AndyB

Well-known member
I would like to be able to replace all the contents in a template using the Create Template Modification system, is this possible?
 
You can maybe do it with a regular expression but unless you're releasing an add on you'd might as well just edit the template directly.

And if you are releasing an add on, don't replace an entire template :p
 
Currently I have my modified templates saved as text files. So when I upgrade I just copy/paste the text files over the default templates after reverting all templates. What I would like to be able to do is save the modified templates in the TMS in the Replace input box, that way when I upgrade it would easier.

Ideally there would be one more radio button that says "Replace entire templete" and it would be positioned where the red arrow is.

pic001.webp
 
This should work:

Set it to Regular Expression and,

Find: /(.*?)/is
Replace: <blank>

As it happens, this has just helped me find a potential bug...

It works, though.
 
that way when I upgrade it would easier.
Not really.

If the template is marked as outdated, unless you use the automatic merge feature you will have to do a diff compare yourself and manually edit your replacement code to update it to the latest version.
 
And actually it's a bit of a misnomer that the TM system is useful in situations like this. If you're replacing an entire template in this way, it will just be even more difficult to merge any updated templates into it. If a future version of XenForo introduces new functionality or fixes in the templates you entirely replace then you will have to still do some sort of comparison. But in the TM system interface there is no useful diff/merge functionality in this regard.

As Brogan says, letting the templates go outdated and then doing a per difference comparison and merge into the updated template is going to be much quicker.
 
This should work:

Hi Chris,

Thank you for taking the time to look into this. I was about to test it and ran into a question. Why isn't there a style version in the TMS? If I want to do a replace for example the ad_above_top_breadcrumb in my style_id 2 I can't do that. It appears only the Default Style style_id 1 can be updated.
 
The XenForo TM system only operates on the Master Style. It isn't style specific.

So, once again, editing the templates is going to be much simpler, flexible and upgrade friendly.
 
The XenForo TM system only operates on the Master Style. It isn't style specific.

So, once again, editing the templates is going to be much simpler, flexible and upgrade friendly.

Yes it appears the TM system would require two modifications to do want I want.

1) Allow replacing all
2) Allow selecting style id

I will just create my own Template Modification script to do what I want.

Thanks, Chris.
 
I think you might need to start from the beginning in terms of the new features in XenForo 1.2.

You're absolutely right that manual template edits aren't great and actually can make life very difficult.

However, XenForo 1.2 includes an excellent new system for handling outdated templates. Let's say, for example, that you added a completely new line of code to a template and XenForo also modifies the template and you do an upgrade.

There will of course be an outdated template. But the difference is, you have the option to go to "Merge Changes".

In Merge Changes, it will show you all of the differences between your version of the template and the new XenForo version.

Look at this screenshot:

upload_2013-7-22_19-52-3.webp

The two lines of code highlighted in yellow are where the XenForo version (parent) differs from the custom version (your own edit).

You get given a very simple choice:

1) Use the parent version and remove your custom changes.
2) Keep your custom version.
3) Keep both versions (this will probably not be a common choice for most things).

To give you an extra level of control, after you have selected one of the options you can actually edit the text directly (maybe you want to add more, or leave yourself a comment or something).

upload_2013-7-22_19-57-27.webp

Finally, note the area in blue? Quite simply this is a custom edit you've made that has automatically merged itself, e.g. there's no conflicts. All you need to do is double check that you still want the custom change. If you don't, you can actually click to edit it or remove it.

Finally, click Merge Changes. Job done.

The benefits are:
  • It's easy to see what's changed in the XenForo template.
  • It's easy to see what you've added to the XenForo template.
  • It's easy to choose what action to take if some of the code conflicts.
  • It's easy to allow it to automatically merge changes.
  • It's easy to make further customisations.
The point I'm trying to make is: It's now easy to make template edits.

I urge you and everyone else. Do not be scared of making template edits anymore. There's an incredible amount of change control.

Even if you do all this and realise you've made a massive mistake and merged a load of stuff you shouldn't, you can just use the template history:

upload_2013-7-22_20-2-9.webp

This is all detailed here:

http://xenforo.com/community/threads/template-merging-and-history.48846/
 
The XenForo TM system only operates on the Master Style. It isn't style specific.

When I'm editing a template in the Default Style, there's a check box with the following message:

"Prevent template modifications from being automatically applied"

So apparently the TM system does apply the changes to the Default Style.
 
Looks like the Template Modification system doesn't apply changes to any of the templates directly, rather it provides instructions in the template_compiled table to find and replace items. However if you make changes in the template those override the TM system.
 
The only way a template change should override a template modification is if your change invalidates the search and the template modification can't find what its searching for.
 
I think you might need to start from the beginning in terms of the new features in XenForo 1.2.

You're absolutely right that manual template edits aren't great and actually can make life very difficult.

However, XenForo 1.2 includes an excellent new system for handling outdated templates. Let's say, for example, that you added a completely new line of code to a template and XenForo also modifies the template and you do an upgrade.

There will of course be an outdated template. But the difference is, you have the option to go to "Merge Changes".

In Merge Changes, it will show you all of the differences between your version of the template and the new XenForo version.

Look at this screenshot:

View attachment 51903

The two lines of code highlighted in yellow are where the XenForo version (parent) differs from the custom version (your own edit).

You get given a very simple choice:

1) Use the parent version and remove your custom changes.
2) Keep your custom version.
3) Keep both versions (this will probably not be a common choice for most things).

To give you an extra level of control, after you have selected one of the options you can actually edit the text directly (maybe you want to add more, or leave yourself a comment or something).

View attachment 51905

Finally, note the area in blue? Quite simply this is a custom edit you've made that has automatically merged itself, e.g. there's no conflicts. All you need to do is double check that you still want the custom change. If you don't, you can actually click to edit it or remove it.

Finally, click Merge Changes. Job done.

The benefits are:
  • It's easy to see what's changed in the XenForo template.
  • It's easy to see what you've added to the XenForo template.
  • It's easy to choose what action to take if some of the code conflicts.
  • It's easy to allow it to automatically merge changes.
  • It's easy to make further customisations.
The point I'm trying to make is: It's now easy to make template edits.

I urge you and everyone else. Do not be scared of making template edits anymore. There's an incredible amount of change control.

Even if you do all this and realise you've made a massive mistake and merged a load of stuff you shouldn't, you can just use the template history:

View attachment 51906

This is all detailed here:

http://xenforo.com/community/threads/template-merging-and-history.48846/

Bear with me here, stumbling through this :)

If I have multiple sites and I'm looking to standardize template modifications across them, is it best to use the above advice (direct template edits) along with parent/child styles, rather than create template modifications and export them via addons?

I imagine the answer is 'yes', but I want to make sure I'm not creating more work for myself.
 
Yes. Though arguably using TMs rather than reproducing the same thing over and over again could be sensible but it's not always a better solution. Ultimately it is better as a developer tool.
 
Top Bottom