2017-02-01 68 views
1

我已經構建了一個非常簡單的模塊,以瞭解如何整合swiftmailer模塊來發送使用自定義樹枝模板的電子郵件。使用Swiftmailer的自定義Drupal 8模塊忽略樹枝模板

設在這裏的默認swiftmailer樹枝模板的副本:包含在文件中 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". 
* 

樹枝文件的名稱是swiftmailer - emailtester .html.twig它位於活動主題/ mytheme/templates文件夾中。

當我執行調用emailtester.module內發送電子郵件,並通過電話走正在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總是回退到使用其全局模板文件。

任何建議將不勝感激。

歡呼聲,

德文

+0

目前遇到完全相同的問題!這是否解決?我會發佈一個解決方案,如果我找到一個! –

+0

啓用樹枝調試註釋並檢查生成的電子郵件html。您的模板名稱是否在FILE NAME SUGGESTIONS下列出? –

回答

2

您可能選擇了錯誤的主題用於電子郵件模板:

enter image description here

如果選擇「當前」,郵件被髮送,而你在管理頁面上,只有來自管理主題的swiftmailer模板將被使用。因此,請確保您選擇包含您的自定義swiftmailer樹枝文件的主題。如果這是您的標準前端主題,則可以選擇「默認」。

當然,您必須將Swiftmailer設置爲Formatter。