Twig as our template engine

These requests for comments/change have lead to an implemented feature that has been successfully merged into the 3.1/Ascraeus branch. Everything listed in this forum will be available in phpBB 3.1.
Post Reply
User avatar
RMcGirr83
Registered User
Posts: 357
Joined: Fri Mar 09, 2007 1:51 am
Contact:

Re: [RFC] Twig as our template engine

Post by RMcGirr83 » Sat Jul 06, 2013 9:15 pm

the inability to in-line edit lines of code in template files?
You can't just append to one instead of injecting a complete different one? Hint, Nathan does this with his advertisement management mod IIRC.
Do not hire Christian Bullock he won't finish the job and will keep your money

User avatar
Arty
Registered User
Posts: 970
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

Re: [RFC] Twig as our template engine

Post by Arty » Sat Jul 06, 2013 10:13 pm

RMcGirr83 wrote:
the inability to in-line edit lines of code in template files?
You can't just append to one instead of injecting a complete different one? Hint, Nathan does this with his advertisement management mod IIRC.
No, that's completely different. Appending code does not solve problem of adding custom HTML code to specific places.

For example, lets take this reply form. What if I want to add new form field before subject? Or maybe after subject? It can't be done by appending code at the end of template, it requires injecting code in middle of existing template.

Other forum software solve that by allowing extensions to replace template code before compiling it and/or before displaying it. Old template engine was designed in such way that it was completely impossible to implement such events. That is a huge problem with template engine that must be solved.

Without it we won't have a modern extensions system. If mod authors will require users to apply manual edits to templates, extensions system fails.

So I also wonder if TWIG implementation can handle it. If not, it is still a major improvement over old template engine but it doesn't improve current extensions engine.
Formerly known as CyberAlien.

Free phpBB styles | Premium responsive XenForo styles

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: [RFC] Twig as our template engine

Post by EXreaction » Sat Jul 06, 2013 10:53 pm

VSE+ wrote:What I want to know is, does the new TWIG engine (by the way the amount of work you did on this Nathan is awesome) address the biggest limitation of the template system for extension developers: the inability to in-line edit lines of code in template files?
What do you mean edit lines of code in template files? Are you talking about editing existing template code, say in overall_header.html, in a template event? If so, not really. Altering existing code is a very difficult problem that doesn't really have any good solution I know of.

Hopefully, we'll start using blocks in our templates after Twig is merged, which will help make templating much more flexible and cleaner, but that will only be useful in your own template files, not in the phpBB template files.

Altering code is a bit troublesome, not only is it a bit hacky to begin with and prone to errors, but also priority has to be dealt with properly and conflicts can cause huge issues.

Rather than so much static HTML we are better off designing better code from the backend to allow customization rather than require it be done in template files. From Arty's example, if we were using dynamic forms for everything, that would be super easy and wouldn't even require any template code be generated to output, just a single line of PHP to add an element to the form. This is much less likely to cause conflicts and problems than modifying the HTML output.

Danielx64
Registered User
Posts: 304
Joined: Mon Feb 08, 2010 3:42 am

Re: [RFC] Twig as our template engine

Post by Danielx64 » Sun Jul 07, 2013 12:25 am

EXreaction wrote:Where is that thread?

Everything functions about the same for extensions, except there were some bugs fixed and previously incorrect behavior corrected.
This: https://github.com/nickvergessen/howto- ... phpbb31ext

I was on my phone at the time.

User avatar
VSE
Extension Customisations
Extension Customisations
Posts: 670
Joined: Mon Mar 08, 2010 9:18 am

Re: [RFC] Twig as our template engine

Post by VSE » Sun Jul 07, 2013 1:30 am

EXreaction wrote:What do you mean edit lines of code in template files? Are you talking about editing existing template code, say in overall_header.html, in a template event? If so, not really. Altering existing code is a very difficult problem that doesn't really have any good solution I know of.
Yes, for example, say you create an extension, and you want to add a new class to the anchor tags for topic titles in the core template files (i.e.: viewforum.html). There is no way to do that with the extension system. I've had to resort to jQuery in order to pull of certain code injections/manipulations like that, but client-side techniques like that are not always the ideal solution.

Arty wrote:Other forum software solve that by allowing extensions to replace template code before compiling it and/or before displaying it. Old template engine was designed in such way that it was completely impossible to implement such events. That is a huge problem with template engine that must be solved.
That would be awesome! If an extension could simply replace existing blocks, that would truly allow extension builders to all the flexibility they had as with the ld MODs system :)
Has an irascible disposition.

User avatar
Kamahl19
Registered User
Posts: 161
Joined: Thu Dec 27, 2007 10:31 am

Re: [RFC] Twig as our template engine

Post by Kamahl19 » Sun Jul 07, 2013 2:15 am

Replacing block is great but.. what if you want to install 2 extensions which replace the same block. One of them will not work. How will you explain this to not skilled admins? We have similar problem with phpBB Social Network, we replace the old simple profile with extended SN profile, but all modifications like Karma, Medals etc dont work on profile anymore.

User avatar
Arty
Registered User
Posts: 970
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

Re: [RFC] Twig as our template engine

Post by Arty » Tue Jul 09, 2013 2:12 am

After checking implementation and twig structure, I think it is possible to add pre-compile event (allowing to change source code before compiling it) and post-display event (allowing to change output). That should solve all problems.
Formerly known as CyberAlien.

Free phpBB styles | Premium responsive XenForo styles

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: [RFC] Twig as our template engine

Post by EXreaction » Tue Jul 09, 2013 3:27 am

Sure, events could be made to do that easily enough, but the real problem is that modifying strings is very prone to errors, especially on template code when there are other extensions or customizations installed. We don't want to add support for hacking code when the only time it will be certain to work is on a completely unmodified board with no other extensions installed. Supporting this would just cause a nightmare for both board owners and extension authors trying to assist them.

Instead of modifying existing HTML through string comparisons at render time, edits should just be made to the code itself to prevent problems and allow the board owner to set it up as their board requires. We're trying to have events wherever reasonable, but we don't expect 100% of alterations to boards to be do-able in extensions (though we can hope for > 99%).

User avatar
Arty
Registered User
Posts: 970
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

Re: [RFC] Twig as our template engine

Post by Arty » Tue Jul 09, 2013 8:49 am

It works very well for all commercial forum packages. Conflicts do happen, but they are extremely rare and almost always caused by add-on author replacing huge blocks of template code without actual need to do so. So if conflicts do happen, it is almost always mod author's fault.
Formerly known as CyberAlien.

Free phpBB styles | Premium responsive XenForo styles

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: [RFC] Twig as our template engine

Post by EXreaction » Tue Jul 09, 2013 3:30 pm

What is it exactly that the other forum software does that allows you to modify the HTML? Do you have any examples to show what is being done/how it's being done?

Post Reply