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
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 »

XenForo events:
  • template_post_render($templateName, &$content, array &$containerData, XenForo_Template_Abstract $template) - Called after a template is rendered.
    See this screenshot for detailed description:
    template_post_render.png
    (34.52 KiB) Downloaded 4045 times
    That event is used to change HTML output. Typical add-on would just do search/replace stuff. To generate stuff for replacement its ether hardcoded (usually, but not best method) or event listener parses another template and uses its output to replace code.
  • template_create(&$templateName, array &$params, XenForo_Template_Abstract $template) - Called whenever the template object constructor is called. You may use this event to modify the name of the template being called, to modify the params being passed to the template, or to pre-load additional templates as needed.
    Screenshot:
    template_create.png
    (32.71 KiB) Downloaded 4045 times
  • template_hook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template) - deprecated. Used to be event similar to template events in 3.1, but add-on developers rarely used it because it allowed to change code only in few pre-defined places. In 1.2 it still exists, but is being replaced with template modifications (see below).

Then there are template modifications:
tms.png
(33.81 KiB) Downloaded 4045 times
That's the most popular thing among add-on developers. Before XF 1.2 template modifications were not part of XenForo, it existed as third party add-on:
XF URL: http://xenforo.com/community/resources/ ... m-tms.293/
Source code: https://github.com/guiltar/TMS

Add-on authors can use it to replace strings in templates, do regexp replaces and callback replacements. Few screenshots of it in action (for XF 1.1 when it was separate from core):

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 »

This does seem like it may be useful. I think we could do this easily in 3.1 by using php events so it can be done in code, then eventually build a UI for it in the ACP if we want to do it.

Please open a bug ticket to add the PHP events so the raw template code can be modified and the parsed output can be modified.

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

Re: [RFC] Twig as our template engine

Post by Meis2M »

Hi

Fatal error: Class 'Twig_Loader_Filesystem' not found in /home/zohallco/public_html/3.1.dev/phpBB/phpbb/template/twig/twig.php on line 125

in here:
http://php-bb.ir/3.1.dev/phpBB/install/

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 »


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 »

EXreaction wrote:With the Twig PR, the only syntax that has changed slightly is the INCLUDEJS, no longer is it only limited to a path within the style tree (can use @namespace to include files also) and no longer do you need to append template/ to the path.
Can you give just a short example of what this would look like, using @namespace to include a JS (or CSS?) outside the standard style tree?
Has an irascible disposition.

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 »

<!-- INCLUDEJS @foo_bar/file.js -->

Should be:
ext/foo/bar/styles/(style match)/file.js

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 »

EXreaction wrote:<!-- INCLUDEJS @foo_bar/file.js -->

Should be:
ext/foo/bar/styles/(style match)/file.js
Nice. That works... But one thing... It appears it looks all the way into the template folder, i.e.: ext/foo/bar/styles/(style match)/template/file.js I got this error at one point:

Code: Select all

Uncaught exception 'Twig_Error_Loader' with message 'Unable to find template "file.css" (looked into: ./ext/foo/bar/styles/all/template)
Shouldn't it follow the example you posted, only going as deep as the style name folders? Because in its current state,CSS files would need to go in the template folder, not following the standard convention of css going into a theme folder, to work with this method.

Wouldn't we rather be able to do stuff like this:
<!-- INCLUDEJS @foo_bar/template/file.js --> to find: ext/foo/bar/styles/(style match)/template/file.js
<!-- INCLUDECSS @foo_bar/theme/file.css --> to find: ext/foo/bar/styles/(style match)/theme/file.js
and would also allow this:
<!-- INCLUDEJS @foo_bar/assets/plugin.js --> to find: ext/foo/bar/styles/(style match)/assets/plugin.js
Has an irascible disposition.

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 »

Yes, it only checks in the template/ directory right now, missed that part.

This is currently a limitation we know about, but haven't gotten to addressing yet. I don't think we have a ticket open for this yet actually, so you could open one now.

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 »

EXreaction wrote:Yes, it only checks in the template/ directory right now, missed that part.

This is currently a limitation we know about, but haven't gotten to addressing yet. I don't think we have a ticket open for this yet actually, so you could open one now.

http://tracker.phpbb.com/browse/PHPBB3-11727
Has an irascible disposition.

aleha
Registered User
Posts: 143
Joined: Tue Mar 26, 2013 2:19 am

Re: [RFC] Twig as our template engine

Post by aleha »

From page 7,
Kamahl19 wrote:But Twig syntax is available too, right? Will there be some list in wiki, listing all features in both syntaxes?
EXreaction wrote:Technically, yes, but whether or not we want to allow the use of the Twig syntax is another question. That question will be addressed in another RFC before 3.1.0 is released, but we'll wait on asking that until Twig is actually merged into 3.1.
As I take look at the extensions being developed by devs and others, I see only phpBB template engine syntax.
We will be going towards the first beta in one or two months, so would it be safe to assume that you won't endorse usage of plain Twig code over phpBB's own template engine?

Post Reply