[Tutorial] Convert to Twig Syntax

Discussion forum for Extension Writers regarding Extension Development.
User avatar
Kailey
Community Team Leader
Community Team Leader
Posts: 3883
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay

Re: [Tutorial] Convert to Twig Syntax

Post by Kailey »

phpBB syntax

Code: Select all

{LA_ESCAPED_FOR_JAVASCRIPT}
Twig syntax

Code: Select all

{{ lang('ESCAPED_FOR_JAVASCRIPT')|e("js") }}
or
{{ lang('ESCAPED_FOR_JAVASCRIPT')|addslashes }}
General note that as of phpBB 3.3.5, the following is supported:

Code: Select all

{{ lang_js('ESCAPED_FOR_JAVASCRIPT') }}
Kailey Snay - Community Team Leader
Knowledge Base | Documentation | Community rules
If you have any questions about the rules/customs of this website, feel free to send me a PM.

My little corner of the world | Administrator @ phpBB Modders
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco

Re: [Tutorial] Convert to Twig Syntax

Post by 3Di »

General note that as of phpBB 3.3.6, TWIG type casting to float or int is supported.

E.g.: You can just use this in TWIG using the already available config object (for TWIG).

Code: Select all

{% set MY_INT_VAR = config('my_int_config')|int %}

Code: Select all

{% set MY_FLOAT_VAR = config('my_float_config')|float %}
And remove those type cast from PHP and/or JS.

Like using template assign vars in phpBB
'MY_INT_VAR' => (int) $this->config['my_int_config'],
'MY_FLOAT_VAR' => (double) $this->config['my_float_config'],

Or parseInt(X) or parseFloat(X) in JS.

Ref.: https://github.com/phpbb/phpbb/pull/6302

Ask in case.
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
User avatar
Gumboots
Registered User
Posts: 800
Joined: Fri Oct 11, 2019 1:59 am

Re: [Tutorial] Convert to Twig Syntax

Post by Gumboots »

Does anyone know of a good Twig UDL for Notepad++?

I have tried this one and the folding behaviour is totally screwed. Have tried messing with it, but it's being a PITA to fix, so if there is another one that already works that would be useful.
🇺🇦 Слава Україні! 🇺🇦 Героям слава! 🇺🇦
User avatar
GanstaZ
Registered User
Posts: 1213
Joined: Wed Oct 11, 2017 10:29 pm
Location: GZOverse

Re: [Tutorial] Convert to Twig Syntax

Post by GanstaZ »

Download visual studio code & use it instead of notepad++.. it will solve all your problems.
Usus est magister optimus! phpBB pre-Triton & latest php environment.
When answer lies in the question, question becomes redundant!
User avatar
Gumboots
Registered User
Posts: 800
Joined: Fri Oct 11, 2019 1:59 am

Re: [Tutorial] Convert to Twig Syntax

Post by Gumboots »

I find Notepad++ perfectly adequate for everything else.
🇺🇦 Слава Україні! 🇺🇦 Героям слава! 🇺🇦
User avatar
Kailey
Community Team Leader
Community Team Leader
Posts: 3883
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay

Re: [Tutorial] Convert to Twig Syntax

Post by Kailey »

How to convert these? I'm working on a custom style and these are in overall_header.html.

Code: Select all

{$STYLESHEETS}

Code: Select all

<!--[if lte IE 9]>
	<link href="{T_THEME_PATH}/tweaks.css?assets_version={T_ASSETS_VERSION}" rel="stylesheet">
<![endif]-->
Is the first one just your standard template var ({{ $STYLESHEETS }})? The second one, I'm lost due to the inclusion of the brackets.
Kailey Snay - Community Team Leader
Knowledge Base | Documentation | Community rules
If you have any questions about the rules/customs of this website, feel free to send me a PM.

My little corner of the world | Administrator @ phpBB Modders
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 28851
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier

Re: [Tutorial] Convert to Twig Syntax

Post by Paul »

The second one is standard html, and you dont need to change anything to. In this case it is for Internet Explorer 9 and lower, so you probably can remove it anyways
rxu
Extensions Development Team
Posts: 3898
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation

Re: [Tutorial] Convert to Twig Syntax

Post by rxu »

There's also Twig Converter extension which can do it automatically.
User avatar
cabot
Registered User
Posts: 769
Joined: Sat Jan 07, 2012 4:16 pm

Re: [Tutorial] Convert to Twig Syntax

Post by cabot »

Hello,

Code: Select all

{{ definition.STYLESHEETS }}
User avatar
Kailey
Community Team Leader
Community Team Leader
Posts: 3883
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay

Re: [Tutorial] Convert to Twig Syntax

Post by Kailey »

rxu wrote: Wed Aug 21, 2024 5:28 am There's also Twig Converter extension which can do it automatically.
I actually tried that. It left the IE part untouched.
cabot wrote: Wed Aug 21, 2024 8:12 am

Code: Select all

{{ definition.STYLESHEETS }}
Thanks. Twig Converter actually had the same change, so good to know!
Kailey Snay - Community Team Leader
Knowledge Base | Documentation | Community rules
If you have any questions about the rules/customs of this website, feel free to send me a PM.

My little corner of the world | Administrator @ phpBB Modders
User avatar
ssl
Registered User
Posts: 1979
Joined: Sat Feb 08, 2020 2:15 pm
Location: Le Lude, Pays de la Loire - France
Name: Fred Rimbert

Re: [Tutorial] Convert to Twig Syntax

Post by ssl »

Twig converter should have modified like this

Code: Select all

<!--[if lte IE 9]>
  <link href="{{ T_THEME_PATH }}/tweaks.css?assets_version={{ T_ASSETS_VERSION }}" rel="stylesheet">
<![endif]-->
Sorry for my English ... I do my best! :anger_right:

:point_right_tone3: phpBB: 3.3.13 | PHP: 8.3.9
:point_right_tone4: [Kill spam on phpBB] - [Some French translation of extensions]
"Mistress, Mistress someone is bothering me in pm"
User avatar
Gumboots
Registered User
Posts: 800
Joined: Fri Oct 11, 2019 1:59 am

Re: [Tutorial] Convert to Twig Syntax

Post by Gumboots »

Kailey wrote: Wed Aug 21, 2024 5:40 pm
rxu wrote: Wed Aug 21, 2024 5:28 am There's also Twig Converter extension which can do it automatically.
I actually tried that. It left the IE part untouched.
Just remove it. Any code for versions lower than IE9 has been irrelevant for years.
🇺🇦 Слава Україні! 🇺🇦 Героям слава! 🇺🇦

Return to “Extension Writers Discussion”