Twig as our template engine
Re: [RFC] Twig as our template engine
I'd say go for twig.
Re: [RFC] Twig as our template engine
Remember that the target audience for phpbb templates is non-technical users as much as developers.
- Pony99CA
- Registered User
- Posts: 986
- Joined: Sun Feb 08, 2009 2:35 am
- Location: Hollister, CA
- Contact:
Re: [RFC] Twig as our template engine
Sure, but provide a conversion tool that converts phpBB syntax to Twig so that MOD authors don't have to learn a new syntax if they don't want to. As Oleg said, we need to support non-technical users.DavidIQ wrote:I'd go one way or the other, not support both. If the phpBB template syntax is as horrible as it's being made out to be here then go with Twig.
Steve
Silicon Valley Pocket PC (http://www.svpocketpc.com)
Creator of manage_bots and spoof_user (ask me)
Need hosting for a small forum with full cPanel & MySQL access? Contact me or PM me.
Creator of manage_bots and spoof_user (ask me)
Need hosting for a small forum with full cPanel & MySQL access? Contact me or PM me.
- DavidIQ
- Customisations Team Leader
- Posts: 1904
- Joined: Thu Mar 02, 2006 4:29 pm
- Location: Earth
- Contact:
Re: [RFC] Twig as our template engine
The way this RFC was started seems to make non-technical users an afterthought. I suppose that as part of this RFC such a tool would need to be part of it.Pony99CA wrote:Sure, but provide a conversion tool that converts phpBB syntax to Twig so that MOD authors don't have to learn a new syntax if they don't want to. As Oleg said, we need to support non-technical users.DavidIQ wrote:I'd go one way or the other, not support both. If the phpBB template syntax is as horrible as it's being made out to be here then go with Twig.
Steve
- callumacrae
- Former Team Member
- Posts: 1046
- Joined: Tue Apr 27, 2010 9:37 am
- Location: England
- Contact:
Re: [RFC] Twig as our template engine
Easy!Pony99CA wrote:Sure, but provide a conversion tool that converts phpBB syntax to Twig so that MOD authors don't have to learn a new syntax if they don't want to. As Oleg said, we need to support non-technical users.DavidIQ wrote:I'd go one way or the other, not support both. If the phpBB template syntax is as horrible as it's being made out to be here then go with Twig.
Steve
- callumacrae
- Former Team Member
- Posts: 1046
- Joined: Tue Apr 27, 2010 9:37 am
- Location: England
- Contact:
Re: [RFC] Twig as our template engine
Twig is much easier for non-technical users. It has readable documentation (unlike phpBB), thousands of people use it, an most IDEs support syntax highlighting for it.DavidIQ wrote:The way this RFC was started seems to make non-technical users an afterthought. I suppose that as part of this RFC such a tool would need to be part of it.Pony99CA wrote:Sure, but provide a conversion tool that converts phpBB syntax to Twig so that MOD authors don't have to learn a new syntax if they don't want to. As Oleg said, we need to support non-technical users.DavidIQ wrote:I'd go one way or the other, not support both. If the phpBB template syntax is as horrible as it's being made out to be here then go with Twig.
Steve
- DavidIQ
- Customisations Team Leader
- Posts: 1904
- Joined: Thu Mar 02, 2006 4:29 pm
- Location: Earth
- Contact:
Re: [RFC] Twig as our template engine
You saying you can't read these?callumacrae wrote:It has readable documentation (unlike phpBB)
https://area51.phpbb.com/docs/30x/codin ... templating
https://wiki.phpbb.com/Tutorial.Template_syntax
Also you said that the phpBB template syntax is "disgusting". Can you provide a side-by-side comparison to support your claim? I'm just curious to see how much better it is since I've never used Twig.
Re: [RFC] Twig as our template engine
I quite like it and don't know why would someone say that its disgusting.DavidIQ wrote:Also you said that the phpBB template syntax is "disgusting". Can you provide a side-by-side comparison to support your claim? I'm just curious to see how much better it is since I've never used Twig.
However, its outdated, not flexible enough and its custom. Twig is used in other applications, so users who work with other applications don't need to learn it. Twig is way more flexible than phpBB template system could ever be.
I haven't worked properly with twig to list all advantages. Advantages that I see so far:
Filters
Filters are very powerful. You can transform data as needed for specific situation.
For example, escape language variables when used inside JavaScript, which replaces phpBB's LA_* variables. In phpBB 3.0 function LA_* does that for language variables from language pack. However, it can't be used on other variables such as text generated by sprintf(), it can't be used on custom defined variables or anything else.
Examples:
- {{ lang.ignore_post }} =
{L_IGNORE_POST}
- {{ lang.ignore_post|format(post.ignore_url) }} = currently not possible, variable is formatted in viewtopic.php instead and LA_* doesn't work for it.
- {{ lang.ignore_post|e }} =
{LA_IGNORE_POST}
Another example is usernames. Currently in phpBB whenever username should be displayed, such as poster's name in post, phpBB generates several variables: POST_AUTHOR_FULL, POST_AUTHOR, POST_AUTHOR_COLOR, U_POST_AUTHOR. Most of those variables aren't used, making those assignments useless. Set of custom filters can be created for usernames and instead of assigning multiple variables, phpBB can assign only 1 variable: user data. Filter will generate code that user wants, for example:
- {{ post.author|profile('full') }} =
<a href="{postrow.U_POST_AUTHOR}">{postrow.POST_AUTHOR}</a>
- {{ post.author|profile('link') }} =
{postrow.U_POST_AUTHOR}
- {{ post.author|profile('avatar') }} = sample new filter that generates link to user's avatar
Template inheritance
This is main reason I want Twig to be added as soon as possible.
Unlike phpBB's template inheritance, author can overwrite small part of template in child template instead of copying whole template. It can also be used for template events.
Example:
Code: Select all
{% block header %}
code in main style!
{% endblock %}
{% block content %}
content in main style!
{% block content_footer %}
some nested block
{% endblock %}
{% endblock %}
{% block footer %}
{% endblock %}
Code: Select all
{% extends "main.html" %}
{% block footer %}
this is a custom footer in child style. no other part of template was changed!
{% endblock %}
Code: Select all
{% extends "main.html" %}
{% block footer %}
{{ parent() }}
content appended at the end of footer by some extension! no other part of template was changed. this is replacement for events.
{% endblock %}
Formerly known as CyberAlien.
Free phpBB styles | Premium responsive XenForo styles | Iconify - modern open source replacement for glyph fonts
Free phpBB styles | Premium responsive XenForo styles | Iconify - modern open source replacement for glyph fonts
Re: [RFC] Twig as our template engine
And unlike the current implementation of template events, this allows modifying the template, not just adding to it.
But yes, the reasons Arty mentioned are the main ones (although there are many others) as well as wide-adoption; hence encouraging new contributors, better performance and no need to maintain our own templating engine.
Twig uses a more php similar syntax rather than re-inventing the wheel.
so for a loop, its not
Also, it doesn't use
You can also do things like:
or
as you can access methods/properties of an object or items in an array
Languages would probably be fed in as an array or object so that syntax like Arty demonstrated can be used.
But yes, the reasons Arty mentioned are the main ones (although there are many others) as well as wide-adoption; hence encouraging new contributors, better performance and no need to maintain our own templating engine.
Twig uses a more php similar syntax rather than re-inventing the wheel.
so for a loop, its not
Code: Select all
<!-- BEGIN posts -->
{posts.AUTHOR}
Code: Select all
{% for post in posts %}
<li>{{ post.author|e }}</li>
{% endfor %}
<!-- -->
and { }
instead it uses {% %}
for control structure (does something e.g blocks), {{ }}
for variables and {# #}
for comments which get removed when parsing. Then any comments which you wish to remain in the template can use <!-- -->
and not be confused with variables or control structure that wasn't passed etc.You can also do things like:
Code: Select all
{% set foo = 'foo' %}
{% set foo = [1, 2] %}
{% set foo = {'foo': 'bar'} %}
Code: Select all
{{ foo['bar'] }}
{{ foo.bar }}
Languages would probably be fed in as an array or object so that syntax like Arty demonstrated can be used.
Formerly known as Unknown Bliss
No unsolicited PMs please except for quotes.psoTFX wrote: I went with Olympus because as I said to the teams ... "It's been one hell of a hill to climb"
- callumacrae
- Former Team Member
- Posts: 1046
- Joined: Tue Apr 27, 2010 9:37 am
- Location: England
- Contact:
Re: [RFC] Twig as our template engine
If I were a "non-technical user" (we were talking about them earlier), then no, not at all. It also describes itself as "very brief guide". Twig has huge amounts of documentation, and people have also written books on it if people don't like online documentation.DavidIQ wrote:You saying you can't read these?callumacrae wrote:It has readable documentation (unlike phpBB)
https://area51.phpbb.com/docs/30x/codin ... templating
https://wiki.phpbb.com/Tutorial.Template_syntax
Will do laterAlso you said that the phpBB template syntax is "disgusting". Can you provide a side-by-side comparison to support your claim? I'm just curious to see how much better it is since I've never used Twig.