1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.2 Template Modifications and Comparison

Discussion in 'Have You Seen...?' started by Mike, Apr 12, 2013.

  1. Mike

    Mike XenForo Developer Staff Member

    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:


    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:


    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.


    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:
    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: Jun 21, 2013
    Amaury, Scarface, jamalfree and 111 others like this.
  2. oman

    oman Well-Known Member

    Very nice Mike!
    SneakyDave likes this.
  3. Mike

    Mike XenForo Developer Staff Member

    You didn't have enough time to actually read it! :p
    Liam W, wasif, Wuebit and 14 others like this.
  4. oman

    oman Well-Known Member

    Speed reading is fun... But maybe a bit too speedy.
  5. RobParker

    RobParker Well-Known Member

    Looks really useful :)

    Do these (specifically the template diff viewer) apply to anyone editing a template or only to devs in debug mode using the template modification system?
  6. Mike

    Mike XenForo Developer Staff Member

    RobParker likes this.
  7. CyberAP

    CyberAP Well-Known Member

    Are styles allowed to contain TM?
    Arty and Adam Howard like this.
  8. bousaid

    bousaid Well-Known Member

  9. cclaerhout

    cclaerhout Well-Known Member

    Just to check one thing, the post render template hook will still be there isn't it?
    The template hook listener is still convenient to use direct php, are you sure you want to get rid of it?
    ManOnDaMoon, HWS and Jon W like this.
  10. cclaerhout

    cclaerhout Well-Known Member

    Oh an another thing, could there be a callback like in TMS please?
  11. lazer

    lazer Well-Known Member

    Yee-Ha! (y)
  12. Mike

    Mike XenForo Developer Staff Member

    No. You can release a separate add-on if you want, but this is mostly targetted at add-ons.

    Not planning on that because of the potential danger in completely killing an upgrade with that.
  13. cclaerhout

    cclaerhout Well-Known Member

    ? I mean just a callback to make several changes to one template (the same that as TMS actually). How would it be possible to kill an upgrade with this?
    Adam Howard likes this.
  14. Mike

    Mike XenForo Developer Staff Member

    A fatal error will kill the necessary reparse and would potentially be unrecoverable (I suppose I could add a config.php option to disable modifications for that).
    0xym0r0n, HWS and Chris D like this.
  15. Lee

    Lee Well-Known Member

    Looking good, Mike! :)
  16. Alluidh

    Alluidh Well-Known Member

    I would like to see the chosen template complete like here. It is very helpful for bigger changes to see the template code inside the creation
    Adam Howard and HWS like this.
  17. Lisa

    Lisa Well-Known Member

    Need to read it a couple more times to really let it sink in.. too little sleep..... but upon first perusal, looks great (y)
  18. sinful

    sinful Member

    Nice work! (y)
  19. Luxus

    Luxus Well-Known Member

    Will there be some sort of import function for TMS edits or do we have to apply all edits manually?
  20. Chris D

    Chris D XenForo Developer Staff Member

    Still convenient... But I guess if we're talking about passing parameters to templates then that should be done by extending the relevant View class.
    Jon W likes this.

Share This Page