[Info] Changes to twig behavior on loading files in 3.3.9

Discussion forum for Extension Writers regarding Extension Development.
User avatar
Marc
Development Team Leader
Development Team Leader
Posts: 5705
Joined: Tue Oct 30, 2007 10:57 pm
Location: Munich, Germany
Name: Marc

[Info] Changes to twig behavior on loading files in 3.3.9

Post by Marc »

Starting with the twig version used in phpBB 3.3.9, some extensions might display error messages like the following:

Code: Select all

Fatal error: Uncaught Twig\Error\LoaderError: Looks like you try to load a template outside configured directories (../theme/some_file.css) in "@ExtAuthor_ExtName/some_other_file.html"
This is caused by the more restrictive handling of files that are allowed to be loaded by twig.

Lines that can cause this are for example:

Code: Select all

<!-- INCLUDECSS ../theme/foobar.css -->

Code: Select all

{% INCLUDECSS '../theme/foobar.css' %}
One can easily solve this problem by using the extension prefix instead of relative paths:

Code: Select all

<!-- INCLUDECSS @ExtAuthor_ExtName/foobar.css -->

Code: Select all

{% INCLUDECSS '@ExtAuthor_ExtName/foobar.css' %}
Other includes like INCLUDEJS or the twig include will be affected by this behavior as well. It's recommended to always use the prefix for your extension as outlined above.
User avatar
GTI
Registered User
Posts: 300
Joined: Mon Aug 24, 2020 4:59 pm
Location: West Sussex
Name: Laura

Re: [Info] Changes to twig behavior on loading files in 3.3.9

Post by GTI »

Marc wrote: Tue Nov 29, 2022 8:33 pm One can easily solve this problem by using the extension prefix instead of relative paths:
<!-- INCLUDECSS @some_extension/foobar.css -->
{% INCLUDECSS '@some_extension/foobar.css' %}

For anyone that may want clarity on 'some_extension'... 'some' represents extension author and 'extension' represents extension name.
Of course, don't forget the underscore between them.

Examples:
<!-- INCLUDECSS @ExtAuthor_ExtName/foobar.css -->
{% INCLUDECSS '@ExtAuthor_ExtName/foobar.css' %}
Most of us will enjoy Christmas in the comfort of our own homes this year, however, sadly, that can't be said for people in the Ukraine who are suffering day after day, due to the Russian invasion.

If you would like to make a small donation to help Ukrainians in their time of need, you can donate to help all Ukrainians via BritishRedCross or you can donate to help the Ukrainian children via Unicef. 🇺🇦 Thank You 🇺🇦
User avatar
pierredu
Registered User
Posts: 1272
Joined: Thu Nov 01, 2012 8:04 am
Location: Paris (France)

Re: [Info] Changes to twig behavior on loading files in 3.3.9

Post by pierredu »

Does this also hold true for INCLUDEJS?
User avatar
Marc
Development Team Leader
Development Team Leader
Posts: 5705
Joined: Tue Oct 30, 2007 10:57 pm
Location: Munich, Germany
Name: Marc

Re: [Info] Changes to twig behavior on loading files in 3.3.9

Post by Marc »

@GTI: Thanks for the hint, updated the first post accordingly.

@pierredu: Yes, those should also be affected. I've added this to the first post as well.
User avatar
CyrusG
Registered User
Posts: 47
Joined: Mon Jan 28, 2019 11:58 am
Location: London

Re: [Info] Changes to twig behavior on loading files in 3.3.9

Post by CyrusG »

Thanks for the reply. Will there be a fix for this that you can download and replace this bug?
User avatar
Crizzo
Translations & International Support Teams Manager
Translations & International Support Teams Manager
Posts: 1745
Joined: Thu Apr 23, 2009 1:20 pm
Location: Stuttgart, Germany
Name: Christian

Re: [Info] Changes to twig behavior on loading files in 3.3.9

Post by Crizzo »

This needs to be fixed in the extension, so the extension authors need to update their code.
My extensions for phpBB: CDB
German phpBB Support at www.phpbb.de
User avatar
CyrusG
Registered User
Posts: 47
Joined: Mon Jan 28, 2019 11:58 am
Location: London

Re: [Info] Changes to twig behavior on loading files in 3.3.9

Post by CyrusG »

I understand. A shame as this worked great under the previous version of phpBB. Most likely this extension will not be updated as the owner seems to have a low profile on the forum and under Github.
User avatar
Crizzo
Translations & International Support Teams Manager
Translations & International Support Teams Manager
Posts: 1745
Joined: Thu Apr 23, 2009 1:20 pm
Location: Stuttgart, Germany
Name: Christian

Re: [Info] Changes to twig behavior on loading files in 3.3.9

Post by Crizzo »

And it is a really easy minor change, so you could do it yourself, too
My extensions for phpBB: CDB
German phpBB Support at www.phpbb.de
User avatar
warmweer
Jr. Extension Validator
Posts: 11660
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Bel ... gium

Re: [Info] Changes to twig behavior on loading files in 3.3.9

Post by warmweer »

CyrusG wrote: Thu Dec 01, 2022 9:50 am I understand. A shame as this worked great under the previous version of phpBB. Most likely this extension will not be updated as the owner seems to have a low profile on the forum and under Github.
The fix is quite simple.
A perfect opportunity to avoid having to wait.

Added: again no notification that a new post was submitted before I submitted mine.
Spelling is freeware, which means you can use it for free.
On the other hand, it is not open source, which means you cannot change it or publish it in a modified form.


Time flies like an arrow, but fruit flies like a banana.
User avatar
Raul [ThE KuKa]
Style Customisations
Style Customisations
Posts: 11137
Joined: Mon Dec 08, 2003 9:24 pm
Location: Spain
Name: Raul Arroyo

Re: [Info] Changes to twig behavior on loading files in 3.3.9

Post by Raul [ThE KuKa] »

Thanks Marc, info added in phpBB Spain.
All unsolicited PMs will be ignored.
:warning: Knowledge Base | Documentation | Board rules | phpBB Styles Rules & Policies | Styles Queue Stats :warning:


If you like my styles, translations, etc. and want to show some appreciation, then feel free to Donate.
:flag_es: phpBB Spain - Online Since 2003 :heart:


User avatar
LukeWCS
Registered User
Posts: 278
Joined: Mon Dec 08, 2014 12:32 pm
Location: Germany

Re: [Info] Changes to twig behavior on loading files in 3.3.9

Post by LukeWCS »

Yesterday we published a variant of Marc's message on phpBB.de. As part of this, I examined in advance what exactly causes the problem when switching from phpBB 3.3.8 to phpBB 3.3.9. Below is the relevant section. The text was translated with Google, please forgive me. ;)
Background

In principle, the error message in question has existed for a long time, precisely since phpBB 3.1.0 (Twig 1.13.2). However, the associated check has changed several times over the years and remained unchanged for a long time with phpBB 3.3 up to and including phpBB 3.3.8 (Twig 2.15.1). However, with phpBB 3.3.9 (Twig 2.15.3) there was a tiny change in the following file, which in combination with relative path specifications then leads to the error message mentioned:

vendor\twig\twig\src\Loader\FilesystemLoader.php (Lines 209-211)

Twig 2.15.1:

Code: Select all

            list($namespace, $shortname) = $this->parseName($name);

            $this->validateName($shortname);
Twig 2.15.3:

Code: Select all

            $this->validateName($name);

            list($namespace, $shortname) = $this->parseName($name);
So this is an unnoticed change in Twig, not an intentional change in phpBB 3.3.9.
Last edited by LukeWCS on Sun Dec 11, 2022 9:21 pm, edited 1 time in total.
May the backup be with you. Always.
User avatar
pierredu
Registered User
Posts: 1272
Joined: Thu Nov 01, 2012 8:04 am
Location: Paris (France)

Re: [Info] Changes to twig behavior on loading files in 3.3.9

Post by pierredu »

Thanks for the precision.
User avatar
Raul [ThE KuKa]
Style Customisations
Style Customisations
Posts: 11137
Joined: Mon Dec 08, 2003 9:24 pm
Location: Spain
Name: Raul Arroyo

Re: [Info] Changes to twig behavior on loading files in 3.3.9

Post by Raul [ThE KuKa] »

About "include" JS info, other example.

Code: Select all

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

Code: Select all

{% INCLUDEJS '@ExtAuthor_ExtName/file.js' %}
All unsolicited PMs will be ignored.
:warning: Knowledge Base | Documentation | Board rules | phpBB Styles Rules & Policies | Styles Queue Stats :warning:


If you like my styles, translations, etc. and want to show some appreciation, then feel free to Donate.
:flag_es: phpBB Spain - Online Since 2003 :heart:


nice100
Registered User
Posts: 22
Joined: Sun Oct 03, 2021 7:58 am

Re: [Info] Changes to twig behavior on loading files in 3.3.9

Post by nice100 »

Can anyone do that for me?
if a donation
I don't know anything about that?
sorry for my bad English
Hopefully it is understood ;)
https://games4you.be
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 28851
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier

Re: [Info] Changes to twig behavior on loading files in 3.3.9

Post by Paul »

You should contact the extension author for support.

Return to “Extension Writers Discussion”