SimpleTemplate
SimpleTemplate is a Java-based template engine. Compared to JSP, its main advantage is the clear separation of page code (most often HTML) and java code.
Hello World
The following template:
<nowiki>
<html>
<body>
Hello {VAR XX}
</body>
</html>
</nowiki>
processed by SimpleTemplate and the following java code:
<nowiki>
TemplateEngine.stFilenamePrefix=
"c:/franksordner/dev/SimpleTemplate/examples/";
TemplateEngine engine=new TemplateEngine();
engine.useTemplate("Hello.tpl");
engine.setVariable("XX","World!");
StringBuffer outb=engine.createOutput();
FileWriter fw=new FileWriter("./output/Hello.html");
fw.write(outb.toString());
fw.close();
</nowiki>
will produce the following text:
<html>
<body>
Hello World!
</body>
</html>
Note that this example is very simple. The power of a good template engine will manifest itself as soon as more complex operations, such as iterative Sections are used. See this example to appreciate the usefulness of SimpleTemplate.