When creating templates for the Email channel, there are some challenges to overcome, particularly in creating Text versions, and managing content in Rich Text fields. This article and accompanying eXtension will explain these challenges and accelerate the process of developing your Outbound Email templates.
Background
The basics of creating templates for Email (with text and html versions) are documented in the standard documentation:
However, this still leaves you with a few challenges, (particularly if you have RTF fields in your schemas):
1. How to display RTF field content (which will contain HTML markup) in a Text version
2. How to ensure images are published
3. How to ensure links and images in RTF content have absolute urls
4. How to ensure links in RTF content are tracked
The following sections will describe how to address these challenges, full source code and compiled TBBs and Function Source assemblies can be downloaded here
Getting started
Using the standard Outbound Email TBBs, and the ones found in the eXtension on this site, create your page and components templates as follows:
Page Template
- Outbound Email Prepare TBB (TBB from eXtension)
- Outbound Email Preprocessing (standard SDL TBB)
- HTML Layout DWT TBB
- [optional] Replace Link Placeholders TBB (TBB from eXtension)
- Email Link Resolver TBB(TBB from eXtension)
- Text Layout DWT TBB
- [optional] Replace Link Placeholders TBB (TBB from eXtension)
- Email Link Resolver TBB(TBB from eXtension)
- Outbound Email Postprocessing (standard SDL TBB)
- Cleanup Template (standard SDL TBB)
Component Template
- HTML Layout DWT TBB
- Text Layout DWT TBB
- Set Output Item By Email Mode TBB (standard SDL TBB)
Separating Text and HTML
In your Page Layout DWTs you need to specify the email mode before rendering component presentations. For example
(HTML)
<!-- TemplateBeginRepeat name="Components" -->
@@SetEmailType('html')@@
@@RenderComponentPresentation()@@
<!-- TemplateEndRepeat -->
(Text)
<!-- TemplateBeginRepeat name="Components" -->@@SetEmailType('text')@@
@@RenderComponentPresentation()@@
<!-- TemplateEndRepeat -->
This means that the same Component Template can output text, or html, depending on the mode set in the page layout which is rendering it.
How to display RTF field content as Text
This problem can be overcome with a custom function implemented as part of a Function Source class, which takes the finds the RTF field, and converts it to text using an XSLT.
Then you can call this in your DWT for Text versions like this:
@@ConvertRTFToText("Body")@@
An example function and XSLT can be found in the Function Source as part of the eXtension.
If your RTF field is multivalue, or part of an embedded field, then you can just use the appropriate XPath equivalent (without namespace) to identify the appropriate field. For example:
@@ConvertRTFToText("Paragraph[2]/Body")@@
How to handle images
The default finish actions TBB will normally ensure that images are published to the webserver, however, when rendering a mailing, the images are not actually published. Some images can be embedded in the email using the @@EmbedImage@@ function, however you probably do not want to embed all images in your mail, as this can make the size of the mail very large.
You will need to ensure that the images are published separately to the webserver. In the case of ´design' images (like a company logo) these can be published as a one-off, and you can probably even hardcode the image url in your templates. In the case that you are reusing web content in your emails, the images will already be published as part of the web pages that use this content.
So you only need to worry if you have images that are specifically used for your mailings only. One option is to publish the mailing pages to a hidden folder on the website, which will ensure that the images are published out.
How to ensure images have absolute urls
The default finish actions will resolve images to relative urls, however in a mailing, we need to have absolute urls. The website root for links and images should be pushed into the package for use in templates, and a post-processing TBB should be used to ensure that all image tags are prepended with this root url. This is performed by the Email Link Resolver TBB in the eXtension .
How to ensure links are absolute and tracked
Links can be tracked using the @@GetLinkTrackingURL@@ function in the DWT, however this cannot be applied to the content of RTF fields, which would be resolved to dynamic component links using the Default Finish Actions TBB. We need to run a TBB to process all links and ensure that they are tracked, and have a absolute url. This is combined with the previously mentioned processing of images in the Email Link Resolver TBB in the eXtension