[Tutorial] Convert to Twig Syntax

Discussion forum for Extension Writers regarding Extension Development.
Kuzia
Registered User
Posts: 30
Joined: Sat Dec 31, 2016 6:59 pm
Location: Moscow
Name: Alex

Re: [Tutorial] Convert to Twig Syntax

Post by Kuzia » Fri May 26, 2017 11:49 pm

What about form tokens? {S_FORM_TOKEN} is still in use?

User avatar
VSE
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 4484
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: [Tutorial] Convert to Twig Syntax

Post by VSE » Sun May 28, 2017 12:13 am

Kuzia wrote:
Fri May 26, 2017 11:49 pm
What about form tokens? {S_FORM_TOKEN} is still in use?
See the very first example in the first post.
Official phpBB Extensions My Extensions & MODs
Please do not PM me for support.
Dictated but not read.

User avatar
3Di
Registered User
Posts: 11880
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milano - Frankfurt
Name: Marco
Contact:

Re: [Tutorial] Convert to Twig Syntax

Post by 3Di » Sun May 28, 2017 1:52 am

Kuzia wrote:
Fri May 26, 2017 11:49 pm
{S_FORM_TOKEN} is still in use?
Just in reply of this question, specifically. Also if it is something that doesn't really IMO belongs to this topic.

YES, it is. And the related PHP side of the medal, that's considered a security issue if missing, beware. :geek:

Twig: {{ S_FORM_TOKEN }}
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades

User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: [Tutorial] Convert to Twig Syntax

Post by javiexin » Fri Jun 30, 2017 5:49 pm

Hello again,

I am trying to do something like this, but I cannot make it to work in Twig.
javiexin wrote:
Fri May 26, 2017 11:46 pm
An interesting effect of this, is that now, in the Twig template syntax, you CAN use language keys with parameters! So you could write something like {{ lang('KEY', 3) }} or even nesting vars, if that is allowed {{ lang('KEY', {{ VALUE }}) }}
This works {{ lang('KEY', 3) }}, but what doesn't work is the nesting of variables as in {{ lang('KEY', {{ VALUE }}) }}, neither using them in set statements {% set newvar = {{ VALUE }} %}.

Any clues?

Thanks a lot.
-javiexin

User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: [Tutorial] Convert to Twig Syntax

Post by javiexin » Fri Jun 30, 2017 6:20 pm

Another question: how to perform simple arithmetics with template variables, like {{ TOTAL }} - {{ USED }} and use the resulting value?
-javiexin

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 2217
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: [Tutorial] Convert to Twig Syntax

Post by kasimi » Fri Jun 30, 2017 6:34 pm

No need for nesting:
  • {{ lang('KEY', VALUE) }}
  • {% set newvar = VALUE %}
  • {{ TOTAL - USED }}
  • {% set newval = TOTAL - USED %}

User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: [Tutorial] Convert to Twig Syntax

Post by javiexin » Fri Jun 30, 2017 6:59 pm

Thanks a lot kasimi!!!

Toxyy
Registered User
Posts: 326
Joined: Mon Oct 24, 2016 3:22 pm

Re: [Tutorial] Convert to Twig Syntax

Post by Toxyy » Sat Jul 01, 2017 1:27 am

How much faster does this make your site/take the load off your server?
I am a web developer/administrator, specializing in forums. If you have work you need done or are too lazy to do, pm me!

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 2217
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: [Tutorial] Convert to Twig Syntax

Post by kasimi » Sat Jul 01, 2017 11:05 am

I haven't done any performance tests but I'd assume it's negligible for two reasons:
  1. As phpBB doesn't differentiate between templates that use phpBB syntax and templates that use Twig syntax, the code that checks for phpBB syntax has to run on all template files, regardless of them using phpBB or Twig syntax.
  2. Once converted, templates are cached. They are not converted for every request.

User avatar
Froddelaar
Registered User
Posts: 503
Joined: Tue Mar 29, 2016 3:45 am
Location: Aalst (Belgium)
Name: Andy Dm
Contact:

Re: [Tutorial] Convert to Twig Syntax

Post by Froddelaar » Fri Jul 14, 2017 6:38 pm

I'm updating my style @ the moment for phpBB 3.2.1 RC1
It's best to convert the whole style to Twig Syntrax then?
I'm A Stupid F*ck.. And Proud Of it!
Download +34.000 arcade extension games @ ~ https://www.froddelpower.be ~

Dutch Extension Translations @ https://github.com/Solidjeuh
Donations are always welcome @ https://www.froddelpower.be/donation

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 2217
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: [Tutorial] Convert to Twig Syntax

Post by kasimi » Sat Jul 15, 2017 8:27 am

It is recommended to not mix them both. Also have a look at the Twig Converter.

User avatar
Froddelaar
Registered User
Posts: 503
Joined: Tue Mar 29, 2016 3:45 am
Location: Aalst (Belgium)
Name: Andy Dm
Contact:

Re: [Tutorial] Convert to Twig Syntax

Post by Froddelaar » Sun Jul 16, 2017 7:21 pm

kasimi wrote:
Sat Jul 15, 2017 8:27 am
It is recommended to not mix them both. Also have a look at the Twig Converter.
Converted all the extensions, styles & admin panel.
No problems so far.. Great ext! 8-)
I'm A Stupid F*ck.. And Proud Of it!
Download +34.000 arcade extension games @ ~ https://www.froddelpower.be ~

Dutch Extension Translations @ https://github.com/Solidjeuh
Donations are always welcome @ https://www.froddelpower.be/donation

Blitze
Registered User
Posts: 318
Joined: Tue Nov 29, 2005 5:06 pm

Re: [Tutorial] Convert to Twig Syntax

Post by Blitze » Mon Aug 14, 2017 4:50 pm

Does phpBB recommend any particular file extension when converting to twig: .html, .twig, .html.twig?

BTW, it appears that template events are currently set to only work with .html.
My Extensions: phpBB SiteMaker

User avatar
3Di
Registered User
Posts: 11880
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milano - Frankfurt
Name: Marco
Contact:

Re: [Tutorial] Convert to Twig Syntax

Post by 3Di » Mon Aug 14, 2017 4:54 pm

.html as usual
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades

User avatar
MarkDHamill
Registered User
Posts: 3325
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Re: [Tutorial] Convert to Twig Syntax

Post by MarkDHamill » Wed Nov 29, 2017 1:19 am

Maybe I'm missing something?

Old code:

Code: Select all

var collapseImageIdAlt = '{LA_DIGESTS_COLLAPSE}';
var collapseImageIdTitle = '{LA_DIGESTS_COLLAPSE}';
Resulting HTML source code generated:

Code: Select all

var collapseImageIdAlt = 'Collapse';
var collapseImageIdTitle = 'Collapse';
New code:

Code: Select all

var collapseImageIdAlt = '{{ lang(DIGESTS_COLLAPSE)|addslashes }}';
var collapseImageIdTitle = '{{ lang(DIGESTS_COLLAPSE)|addslashes }}';
Resulting HTML source code generated:

Code: Select all

var collapseImageIdAlt = '';
var collapseImageIdTitle = '';
Get the latest versions of my Digests and Smartfeed mods and extensions.
Need phpBB services or a phpBB consultant? I offer most phpBB services.

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: No registered users and 7 guests