views:

79

answers:

3

I'm writing a template engine (something that will add data to a template to produce a document, like that used in Active Server Pages or JavaServerPages or PHP - or even shell/bash scripts, ant or Word form letters).

Some examples:

${yourVariableHere}
<TMPL_LOOP NAME=EMPLOYEE_INFO>
<%= toStringOrBlank( "expanded inline data " + 1 ) %>
<% Response.Write "Hello World!" %>
<?php echo "Hello World!\n"; ?>

I'd like to use a syntax that is familiar, so it is quick and easy for users to get started, so I'm looking for the most commonly used and most recognizable syntax for templating (not necessarily the "best" one - just the standard one).

My intended audience is more than just web developers, so I guess I shouldn't be biased towards what they are familiar with (though that's where most templates seem to be used).

What's the best example of such a syntax?

+1  A: 

I do belive the most commonly templating syntax is Smarty (http://www.smarty.net/). I once saw a templating engine for JS that used the same syntax.

<b>Hello Smarty</b>
My name is {$user.fullName} and i'm {$user.age} years old.

Easy and clean ...

Quamis
+1  A: 

The ${yourVariableHere} variant is very common: Apache velocity, Freemarker, UNIX Shell, also used int Apache Ant buildfiles and Springframework bean configurations. It also is more easy to parse (not bound to tag hierarchie, no need to use a dom parser) and will also work with old-style HTML and non-tagged text at all.

Arne Burmeister
+1  A: 

If you're running on the JVM, have a look at the support that Groovy has for templating. It uses the EL syntax with ${} as above for variable replacement from a map, and <% %> for executable code blocks. Maybe you could just use that rather than having to roll your own or, if not, just adopt some of the principles.

http://groovy.codehaus.org/Groovy+Templates

Trevor Tippins