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

Implemented A hook to modify templates just before they are compiled

Discussion in 'Closed Suggestions' started by Vladislav Rastrusny, Nov 30, 2010.

  1. Vladislav Rastrusny

    Vladislav Rastrusny Active Member


    Can we have a hook that will allow us to make changes to templates right before they are compiled? This can be used to build some Template modification system on top of XenForo.

    Addition: I mean to change template source on-the-fly without writing changes to the template source.
    CyberAP and Romchik® like this.
  2. Floris

    Floris Guest

    PHP callback on style settings, as done on node: Pages?
  3. Vladislav Rastrusny

    Vladislav Rastrusny Active Member

    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.
  4. ragtek

    ragtek Guest

    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
        $writer XenForo_DataWriter::create('XenForo_DataWriter_Template');
            if (
    $templateId $this->_input->filterSingle('template_id'XenForo_Input::UINT))
  5. Vladislav Rastrusny

    Vladislav Rastrusny Active Member

    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.
  6. ragtek

    ragtek Guest

    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
  7. ragtek

    ragtek Guest

    i've updated my post
    so new post, to make the people following this, read it again^^
  8. Mike

    Mike XenForo Developer Staff Member

    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.
    Vladislav Rastrusny and ragtek like this.
  9. Vossi

    Vossi Active Member

    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.
  10. Vladislav Rastrusny

    Vladislav Rastrusny Active Member

    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.
    Yoskaldyr likes this.
  11. Brogan

    Brogan XenForo Moderator Staff Member

    This will be possible in 1.2 with TMS.

Share This Page