我已经构建了一个非常简单的模块来学习如何集成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总是回到使用它的全局模板文件。
任何建议将不胜感激。
干杯,
是
在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',
);