SimpleTemplate

SimpleTemplate

SimpleTemplate is a Java-based template engine. Compared to JSP, its main advantage is the clear separationof page code (most often HTML) and java code.

Hello World

The following template:

Hello {VAR XX}

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:

Hello World!Note that this example is very simple. The power of a good templateengine will manifest itself as soon as more complex operations, such asiterative Sections are used. See [http://fgerlach.com/NewsgroupPosting.txt this] example to appreciate the usefulness of SimpleTemplate.

External links

* [http://fgerlach.com/SimpleTemplate.tar.gz SimpleTemplate]


Wikimedia Foundation. 2010.

Игры ⚽ Нужно сделать НИР?

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”