SimpleTemplate
From Wikipedia, the free encyclopedia
| This article is orphaned as few or no other articles link to it. Please help introduce links in articles on related topics. (November 2006) |
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.
[edit] Hello World
The following template:
<html>
<body>
Hello {VAR XX}
</body>
</html>
processed by SimpleTemplate and the following java code:
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();
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.

