问题主题Drupal 8 + SwiftMailer联系电子邮件

时间:2016-08-29 02:33:04

标签: drupal themes swiftmailer drupal-8

我正在尝试使用swiftmailer在Drupal 8网站上设置我的联系电子邮件主题,但是遇到了一些困难。我正在尝试使用swiftmailer的默认主题文件,但它会呈现所有正文。如何单独访问每个字段?

我想做的是这样的事情:

{#
/**
 * @file
 * The default template file for e-mails.
 *
 * Available variables:
 * - subject: The subject.
 * - body: The message content.
 * - message: The $message array created and used in the mail building
 *   procedure. Its content varies between cases, but typically contains at
 *   least the following elements:
 *   - id: The message identifier.
 *   - module: The module that handles the building of the message.
 *   - key: The key of the message.
 *   - to: The recipient email address.
 *   - from: The email address of the sender.
 *   - langcode: The langcode to use to compose the e-mail.
 *   - params: The message parameters.
 *
 * 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".
 *
 * @see template_preprocess()
 * @see template_preprocess_swiftmailer()
 *
 * @ingroup themeable
 */
#}
<html>
<head>
  <style type="text/css">
    table tr td {
      font-family: Arial;
      font-size: 12px;
    }

    td .field {
      width: 50px;
    }
  </style>
</head>
<body>
<div>
  <table width="800px" cellpadding="0" cellspacing="0">
    <tr>
      <td class="field">Nome</td>
      <td>{{ body.name }}</td>
    </tr>
    <tr>
      <td class="field">Email</td>
      <td>{{ body.mail }}</td>
    </tr>
    <tr>
      <td class="field">Motivo</td>
      <td>{{ body.motivo }}</td>
    </tr>
    <tr>
      <td class="field">Titulo</td>
      <td>{{ body.subject }}</td>
    </tr>
    <tr>
      <td class="field">Mensagem</td>
      <td>{{ body.message }}</td>
    </tr>
  </table>
</div>
</body>
</html>

这似乎很简单但是花了太多时间。所有“body.something”都是空白的。

由于

2 个答案:

答案 0 :(得分:0)

message.params中的电子邮件参数通常(当然取决于实施)。我建议您使用message.params来访问所需的变量。

另外,为了提供帮助,您可以使用devel模块并使用{{ dump() }}打印出该主题文件中可用的所有变量,然后从那里发现您的内容。

答案 1 :(得分:0)

变量全部列在模板的顶部......

 * Available variables:
 * - subject: The subject.
 * - body: The message content.
 * - message: The $message array created and used in the mail building
 *   procedure. Its content varies between cases, but typically contains at
 *   least the following elements:
 *   - id: The message identifier.
 *   - module: The module that handles the building of the message.
 *   - key: The key of the message.
 *   - to: The recipient email address.
 *   - from: The email address of the sender.
 *   - langcode: The langcode to use to compose the e-mail.
 *   - params: The message parameters.

您可以在模板中使用如下: -

{{ subject }}
{{ body }}
{{ message.to }}
{{ message.params.YOUR_PARAM }}

等等...

相关问题