nokyc Posted January 5, 2023 Share Posted January 5, 2023 (edited) Prestashop Version 8 PHP Version 8.1.0 I am attempting to extend an email layout following Prestashop documentation but having an issue rendering the template. From my module, I register the hook and define a template. public function hookActionListMailThemes(array $hookParams) { if (!isset($hookParams['mailThemes'])) { return; } /** @var ThemeCollectionInterface $themes */ $themes = $hookParams['mailThemes']; $theme = $themes->getByName('modern'); if (!$theme) { return; } // First parameter is the layout name, second one is the module name (empty value matches the core layouts) $orderConfLayout = $theme->getLayouts()->getLayout('payment', ''); if (null === $orderConfLayout) { return; } //The layout collection extends from ArrayCollection so it has more feature than it seems.. //It allows to REPLACE the existing layout easily $orderIndex = $theme->getLayouts()->indexOf($orderConfLayout); $path = __DIR__ . '/mails/layouts/payment.html.twig'; $theme->getLayouts()->offsetSet($orderIndex, new Layout( $orderConfLayout->getName(), $path, '' )); } Previewing the template from the back office displays the error: Could not find layout file: /Applications/MAMP/htdocs/prestashop8/modules/module-name/mails/layouts/payment.html.twig The template file is located on the path so there is another issue. The error occurs on a call to the render function from src/Adapter/MailTemplate/MailTemplateTwigRenderer.php (line 134) private function render( LayoutInterface $layout, LanguageInterface $language, $templateType ) { $layoutVariables = $this->variablesBuilder->buildVariables($layout, $language); $layoutVariables['templateType'] = $templateType; if (MailTemplateInterface::HTML_TYPE === $templateType) { $layoutPath = !empty($layout->getHtmlPath()) ? $layout->getHtmlPath() : $layout->getTxtPath(); } else { $layoutPath = !empty($layout->getTxtPath()) ? $layout->getTxtPath() : $layout->getHtmlPath(); } try { $renderedTemplate = $this->twig->render($layoutPath, $layoutVariables); } catch (LoaderError $e) { throw new FileNotFoundException(sprintf('Could not find layout file: %s', $layoutPath)); } $templateTransformations = $this->getMailLayoutTransformations($layout, $templateType); /** @var TransformationInterface $transformation */ foreach ($templateTransformations as $transformation) { $renderedTemplate = $transformation ->setLanguage($language) ->apply($renderedTemplate, $layoutVariables) ; } return $renderedTemplate; } On further analysis, I noticed $layoutVariables contained the following: http://localhost:8888/prestashop8//mails/themes payment en-US html What area of the application should be updated to correct the file path to /mails/themes for $layoutVariables["mailThemesUrl"]? Edited January 5, 2023 by nokyc (see edit history) Link to comment Share on other sites More sharing options...
Tom Girou Posted January 9, 2023 Share Posted January 9, 2023 What if you replace DIR . / by $path = 'module:module-name/mails/layouts/payment.html.twig'; ? Link to comment Share on other sites More sharing options...
nokyc Posted January 11, 2023 Author Share Posted January 11, 2023 Hey Tom, thanks for the tip. Unfortunately, that didn't work either. I found an open issue on the github page reporting similar problems. https://github.com/PrestaShop/PrestaShop/issues/30290 Recommended solution from that issue did not work here either. Link to comment Share on other sites More sharing options...
Tom Girou Posted February 2, 2023 Share Posted February 2, 2023 Hello, It seems you didn't replace "module-name" with the name of your module. Link to comment Share on other sites More sharing options...
Ali Samie Posted September 11 Share Posted September 11 @Tom GirouI did as you said and still not working Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now