v4.01 © Fantoosh Software 1998-2001


What are Templates?

One of the great strengths of Dynamic Mailer (ODBC) is that you can create a "template" email which specifies layout, and where fields extracted from your database should appear.  

Your HTML template can be created in any HTML editor, such as Microsoft (r) Front Page.  Plain Text templates can be created in Notepad, or in Microsoft Word (but remember to save as Plain Text!).  

How do I specify dynamic content?

Ok, first here is a simple plain text template example to give you an overview.  If you already know ASP (Active Server Pages) then the concepts should be very familiar, but if you don't know ASP - don't worry - it's very simple! 

Lets imagine that Widgets & Co wish to send a personal email to their customers which lists descriptions and prices of products currently in their Sale.  The template may look something like this: 

<~SQL1 SELECT Product_Name, Price FROM Products WHERE Sale=True ORDER BY Price DESC~>

Dear <~FIELD0 First_Name~>

SALE!!!!!

We are very excited here at Widgets inc.  We have a Sale on and prices have never been cheaper!  Just look at these crazy prices:

<~START1~><~FIELD1 Product_Name~> $<~FIELD1 Price~>
<~LOOP1~>

Don't delay - we can't hold these crazy prices for long!  It is already <~NOW ~>!

Regards,

 

Mr Widget.  

At first glance it may look a little complicated, but lets break it down line by line.  

<~SQL1 SELECT Product_Name, Price FROM Products WHERE Sale=True ORDER BY Price DESC~>

Dynamic content is specified by opening with a "<~" and closing with a "~>".  The tilde (wavy line - ~) will normally be on the middle row of your keyboard beside the return key.  

The system can handle up to 5 SQL statements (more than enough for practically any email purpose).  They are numbered 1 to 5.  

The SQL Statement tells the system to retrieve the Product Name and price FROM the products table, WHERE the Sale flag is set to true, and to ORDER the records in DESCending price order.  

Dear <~FIELD0 First_Name~>

Hang on!  Where did FIELD0 come from?  Well this refers to the Recipient Selection SQL Statement specified in the software.  The selection SQL is not stored in the template since you may want to select the recipients when you actually send the mail.  

You must remember to include any fields referred to in the template in your Selection statement, otherwise an error will occur!  

<~START1~><~FIELD1 Product_Name~> $<~FIELD1 Price~>
<~LOOP1~>

Ok, here is the tricky bit!  START1 tells the program that this is the beginning of a loop.  After all, we don't just want to display the first product on Sale, we want to display them all!  Anything between a <~START1~> and <~LOOP1~> will be repeated for every record selected in SQL1.  Likewise, if we had a second SQL statement called SQL2 then we would specify the loop with <~START2~> and <~LOOP2~>.  

<~FIELD1 Product_Name~> tells the system to substitute the Product_Name field selected in SQL1 and unsurprisingly, <~FIELD1 Price~> returns the Price field from SQL1.  

Notice that there is a carriage return before <~LOOP1~> - otherwise all the products would appear on the same line!  Likewise, there is no space between <~START1~> and <~FIELD1 Product_Name~> - or we would have a blank line before each product!  

NB in HTML, line spaces are ignored, and therefore you would use a <BR> to specify a new line.  

<~NOW ~>

 Simply displays the current date - specified by your System clock. 

 

What tags are available?

<~SQL1 selection statement goes here~>
<~SQL2
selection statement goes here~>
<~SQL3
selection statement goes here~>
<~SQL4
selection statement goes here~>
<~SQL5
selection statement goes here~>

These tags specify the SQL Selection statements used to retrieve data.  To include a field from another SQL statement in your selection use the syntax <~FIELD0 fieldname~*

For example:

<~SQL1 SELECT Product_Name FROM Products WHERE Client_ID=<~FIELD0 ID~* ORDER BY Product_Name ~>

<~FIELD0 fieldname goes here~>
<~FIELD1
fieldname goes here~>
<~FIELD2
fieldname goes here~>
<~FIELD3
fieldname goes here~>
<~FIELD4
fieldname goes here~>
<~FIELD5
fieldname goes here~>

Specifies the field you wish to be displayed.  Field1..5 refer to the statements SQL 1..5, Field0 refers to the Recipient Selection SQL Statement entered into the program itself. 

<~START1~>
<~START2~>
<~START3~>
<~START4~>
<~START5~>

Used to indicate the start of a block which is to be repeated for every record in the appropriate SQL statement (i.e. 1..5)  There is no START0 since within an email there is only one recipient. 

<~STOP1~>
<~STOP2~>
<~STOP3~>
<~STOP4~>
<~STOP5~>

 Used to indicate the end of a block to be repeated for every record in the appropriate SQL statement. 

<~NOW~>

Shows the current system date. 

What if I run out of SQL Statements?

It is unlikely.  However, they can be reused after the loop if required.  

How do I create an HTML template?

You should create the basic template using your chosen HTML editor, in the dynamic area just enter some text so that you can spot it when you come to enter the dynamic statements. 

Now go to view source (if your editor does not support this, open the file in Notepad).  Place your SQL Statements at the top (they don't need to be, but it will make it easier to follow when you come to modify the template). 

Locate where you require dynamic content and include the appropriate tags. 

To create a table for example, you would create one row in your editor, and place the <~START1~> before the <TR> and <~LOOP1~> after the </TR>.  e.g.:

...
<TABLE>
   <~START1~><TR>
   <TD><~FIELD1 Product_Name~></TD>
   <TD><~FIELD1 Price~></TD>
   <~LOOP1~></TR>
</TABLE>
...