This project is read-only.

Mail templates

Topics: Developer Forum
Sep 11, 2008 at 7:32 AM

How do you manage mail templates (for multiple languages)? What I basically want is to define some named templates (for example, forum_reply.tpl). The user must be able to modify the template, but not rename it.

Is there such a system in N2 or do I have to write this myself?

Best regards,

Sep 11, 2008 at 8:09 AM
Hi Geert,$0$0$0$0I built a mailing-system partly based on N2.$0$0In N2 the mails are created based on a fixed HTML template (which could be configurable, but I have not done that).$0$0The customer creates a page in /edit, which is the e-mail template, marks it to be visible on the website or not and then can create a newsletter based on that page.$0$0Administration of e-mails is built next to N2...$0$0$0$0$0No standards in N2 as far as I know of, but I do think it can be built easy.$0$0$0$0Martijn$0
Sep 12, 2008 at 5:49 AM
Thank you.

Currently, I have a website with ~/MailTemplates/ which I dynamically load at the right location. What I want to do is let the user edit the mail templates but not rename them. Maybe it's an idea to add a new editor part that files (templates) can be edited (some kind of on-line file editor).

I will see what I can do (but I have so much to finish already :( )
Sep 12, 2008 at 7:19 AM
For my understanding, how does a .tpl look like? Is it a HTML formatted template?
Sep 12, 2008 at 7:30 AM
Edited Sep 12, 2008 at 7:31 AM
For the moment, they are simple plain text documents. In the future, I want to implement an advanced template loader (actually, I have already written the template loader class).

The template load class can:

1) Load Text Templates (tpl files) and replace values
2) Load Html Templates (htpl files) and replace values
3) Open Word 2007 files (docx files) and replace values

This way, the system could be easily extended, for example with default template messages. But the Word 2007 functionality makes it possible to create invoices at run-time without having MS Word installed.

What would be great is this if you can create this:


Then, a mail is created with the 2 templates (html and text message). The user will receive the part that is supported by their mail application.
Sep 12, 2008 at 9:39 AM
Sound nice!$0What is the need of actually storing files? Why not store file-content in the database...related to a contentitem it would be good enough to use ?$0
Sep 12, 2008 at 11:35 AM
Well, I wrote this stuff before I began using N2. Also, it's hard to maintain Word documents when they are located inside a database.

Of course, the ideal way is to store the items in the database. However, 2 things:

1) Templates should always be there, and should not be removed (only edited).
2) You need to created an editor for every file type

When you open the file (normally in your browser), it's hard when editing a docx file (I am not going to write a custom word editor if you don't mind :) ). If you have a good solution for this, that would be great.

I am willing to "donate" my template loader to N2 project (it's not very complicated, but it's something and can be easily extend to support multiple cultures/regions).
Sep 12, 2008 at 12:49 PM
Mmmm...preventing deletion is no problem, that can be done (see here).
On the editor part, I do not agree...text and HTML can be done real easy (N2) and other formats can be done by providing upload/download functionality?
Store the bits & bytes in the database or store them (indeed) as files but linked to a contentitem...edititing is downloading, changing and re-upload...
Sep 12, 2008 at 3:53 PM
Storing data in the database is of course preferred. However, how would you implement the downloading, editing and uploading? I know some CMS systems have a custom tooling for this. Remember, "stupid" users must be able to use it as well.
Sep 12, 2008 at 11:06 PM
Perhaps the mail templates could be stored as text available through a content item relevat to the function. E.g. in the wiki there's some fields used in various parts of the module. Can the tpl parser accept strings?
Sep 13, 2008 at 12:04 PM
Well, the replacement itself is very, very simple. You can pass a collection of KeyValuePair with the constant to replace ([NAME]) and the value (Geert). Then, depending on the document type (text of Word 2007), the replacer is smart enough to replace the text.

Currently, you only have to pass the template name because you can define the templates location (and the TemplateLoader automatically loads the templates from that directory). But, it's easy to split up the replacing and the loading so you can pass text as well.