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
MichaelC
Development Team
Development Team
Posts: 889
Joined: Thu Jan 28, 2010 6:29 pm

Twig as our template engine

Post by MichaelC »

Currently we use our own templating engine; this presents a few issues:
  • Developers from outside of phpBB have to learn it - Whilst it is relativley easy to learn, it is still a barrier.
  • We have to develop it ourselves - This means more wasted development time that could be spent on more helpful/useful features or on other bugs
  • Helpful features don't get added because although they'd be nice/helpful; its not needed
Twig is a relatively easy to learn & very popular template engine. Its used by a lot of frameworks (especially symfony).

There are two options:
  • Use it as a backend with a lexer - This means we use our current syntax in templates, but the backend is deal with by twig. Meaning we get speed and maintenance improvements (although not as much as using twig raw) but we don't get the advantage of people not learning a new template syntax.
  • Twig through and through - Changing to use twig template syntax and structure (blocks & hireachy etc.), anything additional we need that is not in twig we can add to twig or build a little twig extension to do it.
As there have been many changes to the current styles in 3.1 (imagesets etc.) it would make sense to try and break all BC at the same time (this will happen for either option); but this depends on time constraints and obviously when 3.1 hits alpha.
Formerly known as Unknown Bliss
psoTFX wrote: I went with Olympus because as I said to the teams ... "It's been one hell of a hill to climb"
No unsolicited PMs please except for quotes.

Senky
Extension Customisations
Extension Customisations
Posts: 315
Joined: Thu Jul 16, 2009 4:41 pm

Re: [RFC] Twig as our template engine

Post by Senky »

Even though I havent tried Twig on any live project yet, I think it has quite complicated syntax without any reason. Especially, I do not like that percentage signs, they are quite annoying, on the other hand, phpBB's current syntax is not much simpler.
I like Twig is extensible and can be rewritten to use our syntax, however, what about considering Smarty? I do not know full features of Twig, so if someone knows both Twig and Smarty, he could express if we can gain more advantages on Twig or Smarty. I propose this just to consider another really nice and simple template system...

User avatar
MattF
Extension Customisations
Extension Customisations
Posts: 675
Joined: Mon Mar 08, 2010 9:18 am

Re: [RFC] Twig as our template engine

Post by MattF »

Any 3rd party template system will add more MB overhead to an already memory-hungry phpBB, and phpBB3.1 is already a RAM hog from what I have tested:
phpBB 3.0.11 index page uses 4.97 MB
phpBB 3.1 index page uses 8.87 MB

Also, didn't the template system in phpBB just get a complete overhaul for 3.1? Seems like a lot of wasted work to propose moving to another now. Also, after years of working with it, I think phpBB's current system is very familiar to developers, and it's gonna be a steep enough of a learning curve for any developers to learn phpBB 3.1. Just doesn't seem like a good idea now to throw in a new templating system to me. Perhaps maybe for phpBB 4.
Has an irascible disposition.

User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 1904
Joined: Thu Mar 02, 2006 4:29 pm
Location: Earth
Contact:

Re: [RFC] Twig as our template engine

Post by DavidIQ »

+1 for phpBB 4. This is too big of a change to throw it at the community for the 3.x line.
Image

User avatar
MichaelC
Development Team
Development Team
Posts: 889
Joined: Thu Jan 28, 2010 6:29 pm

Re: [RFC] Twig as our template engine

Post by MichaelC »

VSE+ wrote:Any 3rd party template system will add more MB overhead to an already memory-hungry phpBB, and phpBB3.1 is already a RAM hog from what I have tested:
phpBB 3.0.11 index page uses 4.97 MB
phpBB 3.1 index page uses 8.87 MB
The oppisite. ;) Using twig is faster. Igorw did a POC which proved that if I recall correctly.
DavidIQ wrote:+1 for phpBB 4. This is too big of a change to throw it at the community for the 3.x line.
Its long been decided that we should just make larger changes in 3.x rather than rewrite for 4.0. Rewriting phpBB will simply never happen? Anyway, the 1st option wouldn't be much of a change at all. The 2nd change isn't much of a difference. Its just changing the template syntax which isn't a very large change if I'm honest, it would just have a large diff.

From {VAR} to {{ VAR }} and <!-- IF blah eq 'no' --> to {% if blah == 'no' %} (Which is basically php's syntax and is less chars). The only difference would be blocks. But we don't have to use them as it still supports including files. However its just better to have a layered architecture with blocks.
Also, didn't the template system in phpBB just get a complete overhaul for 3.1? Seems like a lot of wasted work to propose moving to another now. Also, after years of working with it, I think phpBB's current system is very familiar to developers, and it's gonna be a steep enough of a learning curve for any developers to learn phpBB 3.1. Just doesn't seem like a good idea now to throw in a new templating system to me. Perhaps maybe for phpBB 4.
That shouldn't be a reason to implement or not implement something. Work has and always will not get used. Its how development works. Because work has been done on something doesn't mean we shouldn't use a better solution.

As for learning curve, if you know PHP it will take you 5 minutes. If you knew phpbb's old template syntax but not PHP it will take you 15 minutes.
Senky wrote:Even though I havent tried Twig on any live project yet, I think it has quite complicated syntax without any reason. Especially, I do not like that percentage signs, they are quite annoying, on the other hand, phpBB's current syntax is not much simpler.
I like Twig is extensible and can be rewritten to use our syntax, however, what about considering Smarty? I do not know full features of Twig, so if someone knows both Twig and Smarty, he could express if we can gain more advantages on Twig or Smarty. I propose this just to consider another really nice and simple template system...
Smarty is neither as widely used, is slower and not as powerful (off the top of my head).
Formerly known as Unknown Bliss
psoTFX wrote: I went with Olympus because as I said to the teams ... "It's been one hell of a hill to climb"
No unsolicited PMs please except for quotes.

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 »

I like the idea, but I do not know about using it for 3.1.

3.1 only needs a few things that are keeping it from being released. Preferably those would be worked on...

User avatar
Arty
Former Team Member
Posts: 985
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

Re: [RFC] Twig as our template engine

Post by Arty »

I like that idea too, even for 3.1.

If you can replace template engine with twig, rewrite all templates using twig syntax (I know its possible to change twig to work with current template syntax, but i think its a bad idea) for 3.1, I don't see why it can't be included in 3.1 too.

User avatar
Meis2M
Registered User
Posts: 451
Joined: Fri Apr 23, 2010 10:18 am
Contact:

Re: [RFC] Twig as our template engine

Post by Meis2M »

+1 for 3.1

is it like wordpress template?

User avatar
Arty
Former Team Member
Posts: 985
Joined: Wed Mar 06, 2002 2:36 pm
Location: Mars
Contact:

Re: [RFC] Twig as our template engine

Post by Arty »

Meis2M wrote:is it like wordpress template?
No, nothing like that. Why did you say "+1" if you have no clue of how it works?

User avatar
RMcGirr83
Registered User
Posts: 360
Joined: Fri Mar 09, 2007 1:51 am
Contact:

Re: [RFC] Twig as our template engine

Post by RMcGirr83 »

Work has and always will not get used. Its how development works. Because work has been done on something doesn't mean we shouldn't use a better solution.
Hmmm, I sort of recall that this reasoning was used to retain subsilver2. Paraphrase "The work has been done on subsilver so we should keep it".
Do not hire Christian Bullock he won't finish the job and will keep your money

Post Reply