Customizing the Mailer Template

by Sam Knox last modified Dec 30, 2008 05:51 PM
How to customize the mailer adapter template to include your own message and how to include mail merge-like dynamic content.

If you wish to customize the mailer adapter, you must have some familiarity with HTML, and TALES preferably. To get started, edit the Mailer Adapter and click on the Template tab to see the email template.

You should see a chunk on HTML and TALES similar to the screen shot below. The default template is designed to grab all three plain-text fields found in the Message tab, and display all the form data that the site visitor submitted. If you do not put any text into the Message fields (prepend, append, and signature), no text will render so it is not necessary to remove those lines of code.

mailer-adapter-template.gif

However, if you do not want the form data to be part of your email message, you can remove the definition list that renders this information. The code in question is the following:

    <dl>
        <tal:block repeat="field options/wrappedFields">
            <dt tal:content="field/fgField/widget/label" />
            <dd tal:content="structure python:field.htmlValue(request)" />
        </tal:block>
    </dl>

Simply highlight and remove this block of HTML and you're all set. Now you can enter your own HTML and TALES code to create a customized email message. Use only non-deprecated HTML tags to format your message.

If you wish to include dynamic content in the template you must be familiar with TALES. Below is an example of a TALES expression that grabs the first-name field data and puts it into the email template.

<tal:block tal:content="python:request.form.get('first-name', 'Supporter')"/>

'first-name' is the shortname of the First Name string field. 'Supporter' is the default value that will be used if no First Name data is submitted. For required fields, it's probably not necessary to define a default value.