Skip to content

Use the @Modules Twig namespace for mail layouts added from a module - #2165

Draft
boo-code wants to merge 1 commit into
PrestaShop:9.xfrom
boo-code:fix/mail-layout-twig-namespace-30290
Draft

Use the @Modules Twig namespace for mail layouts added from a module#2165
boo-code wants to merge 1 commit into
PrestaShop:9.xfrom
boo-code:fix/mail-layout-twig-namespace-30290

Conversation

@boo-code

@boo-code boo-code commented Sep 5, 2026

Copy link
Copy Markdown
Questions Answers
Branch? 9.x
Description? Both pages that show a module supplying its own mail Layout build the path with _PS_MODULE_DIR_, i.e. an absolute filesystem path. MailTemplateTwigRenderer passes that value to Twig\Environment::render(), which resolves template names, so an absolute path raises "Unable to find template" - the "Could not find layout file" in the report. Measured with a loader configured like the renderer's: the absolute name fails while @Modules/... and a path relative to a registered Twig path both render. The two pages now use the @Modules namespace.
Fixed ticket? Fixes PrestaShop/PrestaShop#30290
Sponsor company

Why the core issue needs no core change

The code half of #30290 was already fixed: PR #38304 ("Fix mail theme scanner when used on a module
folder", 47a434d1143b, base 9.0.x, first release tag 9.0.0, present on upstream/9.2.x) makes
FolderThemeScanner emit @Modules/<relative> instead of @MailThemes when it scans a module folder.

What remains is a module supplying its own Layout path, which is what the docs teach - and the docs
still teach the broken form. Two earlier PRs (#30295, #31987) were closed, the second with kpodemski
pointing at #38304.

Measured

MailTemplateTwigRenderer:118 calls $this->twig->render($layoutPath, ...), so the path is a Twig
template name
, not a filesystem path. With a loader configured like the renderer's:

/tmp/tw/mails/layouts/order_conf.html.twig     LoaderError: Unable to find template
@Modules/mails/layouts/order_conf.html.twig    renders
mails/layouts/order_conf.html.twig             renders

The file existed and its directory was a registered Twig path - an absolute name still fails, which is
exactly the "Could not find layout file" in the reporter's screenshot.

Scope

bapman81 reported one page; two teach the broken form and both are fixed:

  • modules/concepts/mail-templates/extend-a-layout-from-module.md:101
  • modules/concepts/mail-templates/add-a-layout-from-module.md:123

Each now uses '@Modules/' . $this->name . '/mails/layouts/...' - $this->name rather than a hard-coded
folder, so the example stays correct whatever the module is called - plus a {{% notice tip %}} block
explaining that the path is a Twig template name. The notice shortcode matches the repo's existing style
({{% notice tip %}} is used 35 times under modules/).

Both mail-template pages build the layout path with __DIR__, which cannot
work: the path is a Twig template name, handed straight to
Twig\Environment::render() by MailTemplateTwigRenderer. An absolute path is
looked up under the registered Twig paths, not opened from disk, so it raises
LoaderError and the preview shows "Could not find layout file".

Verified against Twig 3 with a loader configured the way the mail renderer's
is - the file existing and its directory being a registered path is not
enough:

  /tmp/tw/mails/layouts/order_conf.html.twig     LoaderError: Unable to find template
  @Modules/mails/layouts/order_conf.html.twig    renders
  mails/layouts/order_conf.html.twig             renders

Reported in PrestaShop/PrestaShop#30290, where the working form was found by
0x346e3730 in 2022 and asked for again by bapman81 in 2025.
@github-actions github-actions Bot added the 9.x label Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Email previsualisation of module throw an error

1 participant