Tmplz Template API

Getting Started

Section

The Section class is analagous to the Section template tag; every Section in a template is represented in the Tmplz API as an instance of the Section class. The entire template itself is an instance of Section as well.

Section.show()

The Section.show() method obtains a Section nested within the current Section, makes it visible, and returns it. (Note that the template Section itself is automatically "shown" when it is obtained from the TemplateManager).

  //Show the "Row" Section three times, and within each of those, 
  //show the "Col" section twice:
  for (int i=0; i<=3; i++) {
    Section row=template.show("Row");
    Section col1=row.show("Col"),
            col2=row.show("Col");
  }

Every time a Section is repeated, it makes a copy of itself and appends the copy to itself. Each copy has its own internal Sections & Slots.

Section.fillin()

The Section.fillin() method fills in named Slots in the template. For example:

  //Fillin the slot "FullName" with the value "Mr. Jones":
  mySection.fillin("FullName", "Mr. Jones");

Printing the template

The Section.appendTo() method prints the Section to any instance of java.lang.Appendable (including java.io.Writer, System.out, java.lang.StringBuilder, etc.). So one can print an entire template, or just a specific Section obtained from a template. Section.toString() will also "print" the Section (to a single String result), but appendTo() is more efficient when writing the template to a stream.

  //Print the template to System.out:
  myTemplate.appendTo(System.out);

Next page: Additional Classes & Things