Tmplz Template API

Getting Started

Introduction

This tutorial explains how to get started with Tmplz, and provides links to the most important Java classes. Fortunately there are no special XML files to configure; everything is done in Java code. The binary distribution contains two .jar files, tmottecommon.jar and tmplz.jar. These should go in the classpath of an application that will use Tmplz.

Code example for the impatient

The following obtains a template, does a few things with it, and prints it.

  package org.tmotte.tmplz.test;
  import org.tmotte.tmplz.Section;
  import org.tmotte.tmplz.TemplateManager;
  import org.tmotte.tmplz.load.builtin.FileTextLoaderFactory;
  public class DocExample {
    public static void main(String[] args) {
      TemplateManager templateMgr=new TemplateManager();
      templateMgr.getTextLoadMgr().register(new FileTextLoaderFactory());
      Section template=templateMgr.getTemplate("test.html");
      for (int i=0; i<5; i++){
        Section s=template.show("item");
        s.fillin("number", i);
      }
      template.appendTo(System.out);
    }
  }

For the above example to work, the source code for test.html could look something like this:

  Here are some numbers: 
    [$Section item]<p>[$Slot number]</p>[$Section]

For a more in-depth explanation, read on.

Next page: TemplateManager