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"]?