Creating Email Templates


CustomTemplates.xslt extends the Cartella email system by making it possible to create custom emails. EmailContentController, a C# class in Cartella, handles custom emails.

To create a custom email template:
  1. Call the SendMail method on the EmailContentController class, passing in the value of emailContentKey to the SendMail method.
    The SendMail method sends the following information to the CustomTemplates.xslt stylesheet for processing:
    <CartellaEmail>
        <URL>http://www.mydomain.com</URL>
        <Content EmailType="emailContentKey">
            <Key1><![CDATA[Value1]]></Key1>
            <Key2><![CDATA[Value2]]></Key2>
        </Content>
    </CartellaEmail>
    • Base URL: This is the URL of the server where your instance of Cartella lives. You need this URL for adding links to, and images from, the Cartella site. For example, you can add an image to your email by using the following code: <img src="{@URL}/Images/MyImage.jpg"/>
    • Type of Email: This is the value of the EmailType attribute in the <Content> element. It will be populated with the value of emailContentKey that is passed to the SendMail method.
    • Content: The inner value of the <Content> node is populated from the variableToValue dictionary that is passed to the SendMail method. Each key in that dictionary becomes an element, with each value populated with the value from the dictionary.
      Note
      If you would like to add your own dictionary inside the <Content> tag, make sure to use the XmlSerializableDictionary class. Remember that ToString will be called to get the keys and values. Make sure that the key will become a valid XML element name.
  2. Make the appropriate change to the sample template in the CustomTemplates.xslt stylesheet.
    <!-- Sample Template -->
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        exclude-result-prefixes="xs"
        version="2.0">
     <xsl:template match="Content[@EmailType='emailContentKey']">
        Here is the value of Key1: <xsl:value-of select="Key1"/><br />
        Here is the value of Key2: <xsl:value-of select="Key2"/><br />
        Here is the value of Key3: <br />
        <xsl:for-each select="Key3/*">
            <xsl:value-of select="name()"/>:<xsl:value-of select="."/>
            <br />
        </xsl:for-each>
    </xsl:template>   
    </xsl:stylesheet>
  3. Save CustomTemplates.xslt.