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

Discussion forum for Extension Writers regarding Extension Development.
User avatar
ssl
Registered User
Posts: 1606
Joined: Sat Feb 08, 2020 2:15 pm
Location: Le Lude, Pays de la Loire - France
Name: Fred Rimbert
Contact:

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

Post by ssl »

GTI wrote: Tue Nov 29, 2022 9:29 pm
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' %}
An example with Advanced Polls extension
Sorry for my English ... I do my best!

phpBB: 3.3.11 | PHP: 8.2.16
[Kill spam on phpBB] - [Some French translation of extensions]
"Mistress, Mistress someone is bothering me in pm"
rxu
Extensions Development Team
Posts: 3711
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Contact:

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

Post by rxu »

What's the correct way if you use some external libraries linking their css/js files from "extauthor/extname/vendor/libname", "extauthor/extname/assets" and so on folders?
User avatar
Mick
Support Team Member
Support Team Member
Posts: 26502
Joined: Fri Aug 29, 2008 9:49 am

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

Post by Mick »

nice100 wrote: Fri Dec 02, 2022 2:53 pmCan anyone do that for me?
You can request a donation paid job in the Wanted! forum.
  • "The more connected we get the more alone we become" - Kyle Broflovski©
  • "The good news is hell is just the product of a morbid human imagination.
    The bad news is, whatever humans can imagine, they can usually create.
    " - Harmony Cobel
User avatar
HiFiKabin
Community Team Member
Community Team Member
Posts: 6671
Joined: Wed May 14, 2014 9:10 am
Location: Swearing at the PC, UK
Name: James
Contact:

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

Post by HiFiKabin »

Several off topic posts removed. Please keep to the subject

Thank you

Community Team Member
User avatar
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 5859
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman

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

Post by MattF »

Marc wrote: Tue Nov 29, 2022 8:33 pm 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.
What about when using phpbb\controller\helper\render() such as in a controller PHP file?

For example:

Code: Select all

$this->helper->render('foo_bar.html', $this->language->lang('FOO_BAR'));
Should that be using this syntax instead as well?

Code: Select all

$this->helper->render('@vendor_extension/foo_bar.html', $this->language->lang('FOO_BAR'));
Formerly known as VSEMy ExtensionsPlease do not PM me for support.
User avatar
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 5859
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman

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

Post by MattF »

Just thought I'd make an update here to my above post question.

When calling a template file from PHP (as in my code examples above) consider this:

Template files are searched for two places (and in this order):
  • phpBB/styles/<style_name>/template/
  • phpBB/ext/<all_active_extensions>/styles/<style_name>/template/
Knowing this, if you know you only want to load a template file from your own extension, then use your vend_ext prefix like:

Code: Select all

$this->helper->render('@vendor_extension/foo_bar.html', $this->language->lang('FOO_BAR'));
If you want to load a template that could be located anywhere, i.e: in phpBB's prosilver style, or in your own extension, or somebody else's extension, then omit the vend_ext prefix like:

Code: Select all

$this->helper->render('foo_bar.html', $this->language->lang('FOO_BAR'));
Formerly known as VSEMy ExtensionsPlease do not PM me for support.
User avatar
GanstaZ
Registered User
Posts: 1187
Joined: Wed Oct 11, 2017 10:29 pm
Location: GZOverse

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

Post by GanstaZ »

Maybe your examples should be vice-versa?
Loading a file from someones extension or in one of the addons for one of the extension:

Code: Select all

$this->helper->render('@vendor_extension/foo_bar.html', $this->language->lang('FOO_BAR'));
That way we know what & from where we want to load it & currently render works without issues.. even though it doesn't let us to change template files like we can do in symfony projects, but i guess most can live without it.
Usus est magister optimus! phpBB pre-Triton & latest php environment.
When answer lies in the question, question becomes redundant!
Post Reply

Return to “Extension Writers Discussion”