Overview

Notch's built-in template engine

NotchTemplates is a template engine that composes Notch's tokenizer and expression parser to render text with embedded expressions and commands. Use it when you want a string-output template that can call into Notch evaluation.

A template file is made of three kinds of content:

  • Literal text - copied to output verbatim.
  • Expressions - the form ${ expression } evaluates expression as Notch and substitutes the result. The result is HTML-escaped.
  • Commands - a line that starts with # and a command name, with no space between them, invokes a template command (control flow, layout, macros, etc.). #for is a command. # for is literal text.

The engine lives in the package edu.montana.notch.templates. The main entry points are:

  • NotchTemplates - loads, parses and renders templates. Use renderTemplate(uri, vars) for a template from the loader and renderString(template, vars) for a template in a String.
  • BasicNotchTemplateCommands - the built-in commands. Call BasicNotchTemplateCommands.addTo(templates) to register them. A new NotchTemplates has no commands.
  • NotchTemplateLoader - the base class for a source of template files. Four implementations ship in edu.montana.notch.templates.loader: DefaultNotchTemplateLoader (used by new NotchTemplates()), ClasspathNotchTemplateLoader, FileSystemNotchTemplateLoader and InMemoryNotchTemplateLoader.
  • NotchTemplateCommand - the base class for template commands. Subclass it and register it with addCommand to add your own.
  • RawString - in edu.montana.notch.templates.runtime. A value of this type is written to the output without HTML escaping.

See also