2016-08-29 9 views
1

나는 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"은 비어 있습니다. 이메일에 대한

감사

답변

0

매개 변수는 보통 message.params에 (물론 구현에 따라 다름). message.params을 사용하여 필요한 변수에 액세스하는 것이 좋습니다.

도울 수 있도록 devel 모듈을 사용하고 {{ dump() }}을 사용하여 해당 테마 파일에서 사용할 수있는 모든 변수를 인쇄하고 거기에서 내 소재가 무엇인지 발견 할 수 있습니다.

+0

덤프 (몸)은 일하고 있지만 실제로 관심이 없습니다. dump (message.params)는 아무것도 표시하지 않습니다. –

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 }} 

기타 ...

+0

message.params.field_name이 작동하지 않습니다. 필드가 모두 본문에 한 번 표시됩니다. 필드를 개별적으로 액세스하는 방법을 모르겠습니다. –

+0

템플릿이 캐시되고 있습니까? https://www.drupal.org/node/2598914 – featherbelly

+0

PARAM을 정의하는 메일 보내기 기능이 있습니까? – featherbelly