views:

19

answers:

1

I want to have generalised email templates. Currently I have multiple email templates with some part of the subject and body being changed. I would like to club them together with some conditional branching like,

<email>
   <sub>
      if(condition)
           sub1
      else
           sub2
    </sub>
    <body>
        some text
        if(condition)
             text...
        else
             text...

        body continued...
    </body>
</email>

Can I do this in any way?

A: 

For this task it is a good idea to use a template engine. There exist template engines for plain text (like Apache Velocity) which you can use for generating XML too. There are also specialized template engines for XML, like XSLT (with various implementions for nearly every programming environment) or Genshi (with a special XML mode).

Look at the Wikipedia template engine page for a comparison table.

vanje