Logo         Community
The Company
Your Account
Contact Us
Creating Email Newsletters with patNewsletter (part 2)
Learn to manage subscribers and customize newsletters with patNewsletter.

| Laying It Out |

The layout of your newsletter is driven by the patTemplate template engine. Developed by Stephan Schmidt - the author of patNewsletter - patTemplate is a PHP-based template engine designed, in the author's words, to "help you separate program logic or content from layout". Read more about it at http://www.melonfire.com/community/columns/trog/article.php?id=130

As you might remember from the first part of this article, I specified in the configuration file that all templates would be located in the "templates/" directory, for both administration and subscription interfaces. The templates associated with the newsletter are a part of the administration section of the application and are present in the "admin/templates" directory under the root directory of the application.

Find a file named "patNlNewsletter.txt.tmpl" and open it in your favourite text editor.Here's what you'll see:

<patTemplate:tmpl name="subject" type="condition" conditionvar="SUBJECTPREFIX" whitespace="trim">
<patTemplate:sub condition="default">

<patTemplate:tmpl name="body" whitespace="keep">



In dieser Ausgabe:
<patTemplate:tmpl name="toc">

<patTemplate:tmpl name="details">




A closer look, and you'll see that this template is made up of two distinct sub-templates, one for the body and one for the subject line - pretty much what you would expect for a email newsletter!

Let's take a closer look at each of them, shall we? Here's the sub template for the subject line:

<patTemplate:tmpl name="subject" type="condition" conditionvar="SUBJECTPREFIX" whitespace="trim">
<patTemplate:sub condition="default">

The code here leverages off conditional template support in the patTemplate class. "Conditional templates" function much like a series of "if-else" conditional statements - they allow you to display different output depending on how a particular, user-defined condition is evaluated. A conditional template typically contains a number of sub-templates, each keyed against a particular variable; depending on the value of that variable, the appropriate sub-template is extracted and used.

In the example above, the conditional variable is called "SUBJECTPREFIX" and the only condition allowed, at this point of time, is the default value. But there is still scope for playing around with the template - after a little investigation, I uncovered the six variables that you could include in the subject line:

- name: the name given to the newsletter
- subjectprefix: the prefix provided for the newsletter at the time of creation
- listowner: the email address specified in the "Reply-to address" field
- description: the detailed description about the newsletter
- issue: the issue number associated with the current issue of the newsletter
- subject: the subject specified for this particular issue of the newsletter

If you look at the default template, you will notice that the subject line already contain the issue number, issue subject and the subject prefix. Here is a sample subject line based on the default template:

''.preg_replace(array('/  /', '/ /'), array('  ', '   '), '
[hitg] #2: One Million Or Bust !!

Let's tweak the template and see if we can make things a little more interesting:

<patTemplate:tmpl name="subject" type="condition" conditionvar="SUBJECTPREFIX" whitespace="trim">
<patTemplate:sub condition="default">
Issue # {ISSUE_ISSUE} of "{NL_NAME}" on * {ISSUE_SUBJECT} * by -> {NL_LISTOWNER} <-

Here is the output:

''.preg_replace(array('/  /', '/ /'), array('  ', '   '), '
Issue # 2 of "hitg" on * One Million Or Bust !! * by -> hitg@usa.net <-

Note the use of uppercase characters as well as the curly braces around the variables names. These are some conventions that must be followed across all patTemplate templates.

How to do Everything with PHP & MySQL
How to do Everything with PHP & MySQL, the best-selling book by Melonfire, explains how to take full advantage of PHP's built-in support for MySQL and link the results of database queries to Web pages. You'll get full details on PHP programming and MySQL database development, and then you'll learn to use these two cutting-edge technologies together. Easy-to-follow sample applications include a PHP online shopping cart, a MySQL order tracking system, and a PHP/MySQL news publishing system.

Read more, or grab your copy now!

previous page more like this  print this article  next page
In trog...
Logging With PHP
Building A Quick-And-Dirty PHP/MySQL Publishing System
Output Buffering With PHP
Date/Time Processing With PHP
Creating Web Calendars With The PEAR Calendar Class
In the hitg report...
Crime Scenes
Animal Attraction
Lord Of The Strings
In boombox...
Patience - George Michael
Think Tank - Blur
My Private Nation - Train
In colophon...
Hostage - Robert Crais
The Dead Heart - Douglas Kennedy
Right As Rain - George Pelecanos
In cut!...
American Chai
The Core
Find out how you can use this article on your own Web site!

Copyright © 1998-2018 Melonfire. All rights reserved
Terms and Conditions | Feedback