使用Swiftmailer的自定义Drupal 8模块忽略了twig模板

问题描述 投票:2回答:2

我已经构建了一个非常简单的模块来学习如何集成swiftmailer模块来发送使用自定义树枝模板的电子邮件。

此处的默认swiftmailer twig模板的副本:http://cgit.drupalcode.org/swiftmailer/tree/templates/swiftmailer.html.twig稍作修改,并按照文件本身中包含的说明重命名:

 * This template may be overriden by module and/or mail key, using any of the
 * following template names:
 * - swiftmailer.html.twig: global, used by default.
 * - swiftmailer--mymodule.html.twig: only emails sent by the module "mymodule".
 * - swiftmailer--mymodule--test.html.twig: only emails by the module
 *   "mymodule" with key "test".
 *

twig文件的名称是swiftmailer - emailtester.html.twig,它位于活动的themes / mytheme / templates文件夹中。

当我执行调用以在emailtester.module中发送电子邮件并遍历在Core中的ThemeManager.php,twig.engine.php和Render.php文件中进行的调用时,模板路径指向/ modules /contrib/swiftmailer/templates/swiftmailer.html.twig文件,而不是/themes/mytheme/templates/swiftmailer--emailtester.html.twig文件。

我已经使用drush cr清除了缓存,并清除了config-> performance部分中的所有缓存。我也尝试过清理主题注册表,但似乎没什么好处,因为swiftmailer总是回到使用它的全局模板文件。

任何建议将不胜感激。

干杯,

twig swiftmailer drupal-8
2个回答
4
投票

您可能选择了错误的主题用于电子邮件模板:

enter image description here

如果您选择“当前”并且当您在管理页面上时发送邮件,则将仅使用管理主题中的swiftmailer模板。因此,请确保选择包含自定义swiftmailer树枝文件的主题。如果这是您的标准前端主题,您可以选择“默认”。

当然,您必须将Swiftmailer设置为Formatter。


0
投票

content-type钩子中指定module_mail头之前,不会使用该模板。喜欢:

$headers = array(
    'MIME-Version'              => '1.0',
    'Content-Type'              => 'text/html; charset=UTF-8; format=flowed; delsp=yes',
    'Content-Transfer-Encoding' => '8Bit',
    'X-Mailer'                  => 'Drupal',
);
© www.soinside.com 2019 - 2024. All rights reserved.