5 November 2008

From Organic Design wiki
Warning.svg This is a blog item that needs to be converted to the new Bliki format


EmailPage extension updated to support personalised emails

The EmailPage extension now supports personalised emails. Articles can contain named fields enclosed in braces which we be replaced with specific values for each recipient. The records it draws the data from are in the format used by other extensions such as Semantic Forms and RecordAdmin where each kind of record is a template for example Template:Member whose named triple-brace arguments define the fields of the record. To ensure that it's known to be treated as a record rather than any other template it should be categorised into Category:Records (using noinclude tags). Articles can then become records by transcluding a record template and giving it some specific parameters.

Example record

This example is for those who don't already have a system of maintaining records in wiki articles. First we'll define a new template article called Template:Person containing defining a name and an email address, and a simple layout table so that the record articles are easy to read (the layout in the template doesn't have anything to do with emailing though).

<table>
    <tr>
        <th>Name:</th>
        <td>{{{name}}}</td>
    </tr>
    <tr>
        <th>Email:</th>
        <td>{{{email}}}</td>
    </tr>
</table>
<noinclude>[[Category:Records]]</noinclude>

You can then create as many records as you like for example a new article called Maryjane may contain the following:

{{Person
 | name  = Maryjane
 | email = maryjane@smokyjoes.com
}}
Messages containing fields

Using our new records, we can send an article to the recipients with their proper name in the message, for example our article may contain the following wikitext content:

Dear {name|valued customer},
We'd like to remind you that some say our products can be up to
three times better quality than many other leading brands!

In the EmailPage form, select "Person" from the optional record drop-down box and send as normal. For each recipient, the extension will check if any record (article transcluding Template:Person) have the current email address in their parameters. If so, all the parameter values will be extracted from that article and used to replace the corresponding fields in the content being sent.

Default values can be supplied in case there is no record found, or the record doesn't contain some of the parameters. This is done using the pipe character as in the example above which replaces the name field with "valued customer" if the field can't be replaced. If there is no default, the brace enclosed name will be left unchanged in the content that gets sent.