Use the @Modules Twig namespace for mail layouts added from a module - #2165
Draft
boo-code wants to merge 1 commit into
Draft
Use the @Modules Twig namespace for mail layouts added from a module#2165boo-code wants to merge 1 commit into
boo-code wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Layoutbuild the path with_PS_MODULE_DIR_, i.e. an absolute filesystem path.MailTemplateTwigRendererpasses that value toTwig\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@Modulesnamespace.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, base9.0.x, first release tag 9.0.0, present onupstream/9.2.x) makesFolderThemeScanneremit@Modules/<relative>instead of@MailThemeswhen it scans a module folder.What remains is a module supplying its own
Layoutpath, which is what the docs teach - and the docsstill teach the broken form. Two earlier PRs (#30295, #31987) were closed, the second with kpodemski
pointing at #38304.
Measured
MailTemplateTwigRenderer:118calls$this->twig->render($layoutPath, ...), so the path is a Twigtemplate name, not a filesystem path. With a loader configured like the renderer's:
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:101modules/concepts/mail-templates/add-a-layout-from-module.md:123Each now uses
'@Modules/' . $this->name . '/mails/layouts/...'-$this->namerather than a hard-codedfolder, so the example stays correct whatever the module is called - plus a
{{% notice tip %}}blockexplaining that the path is a Twig template name. The notice shortcode matches the repo's existing style
(
{{% notice tip %}}is used 35 times undermodules/).