[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: 4398
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: 11422
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? You can.
You can pm me only in case of request for paid job. Thx.
MOD conversions, Extensions and Scripts for phpBB.

User avatar
javiexin
Code Contributor
Posts: 1145
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: 1145
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: 1684
Joined: Sat Sep 10, 2011 7:12 pm
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: 1145
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: 264
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: 1684
Joined: Sat Sep 10, 2011 7:12 pm
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: 376
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 +32.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: 1684
Joined: Sat Sep 10, 2011 7:12 pm
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: 376
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 +32.000 arcade extension games @ ~ https://www.froddelpower.be ~

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

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: v12mike and 14 guests