Notch Templates
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 }evaluatesexpressionas 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.).#foris a command.# foris literal text.
The engine lives in the package edu.montana.notch.templates. The main entry points are:
NotchTemplates- loads, parses and renders templates. UserenderTemplate(uri, vars)for a template from the loader andrenderString(template, vars)for a template in aString.BasicNotchTemplateCommands- the built-in commands. CallBasicNotchTemplateCommands.addTo(templates)to register them. A newNotchTemplateshas no commands.NotchTemplateLoader- the base class for a source of template files. Four implementations ship inedu.montana.notch.templates.loader:DefaultNotchTemplateLoader(used bynew NotchTemplates()),ClasspathNotchTemplateLoader,FileSystemNotchTemplateLoaderandInMemoryNotchTemplateLoader.NotchTemplateCommand- the base class for template commands. Subclass it and register it withaddCommandto add your own.RawString- inedu.montana.notch.templates.runtime. A value of this type is written to the output without HTML escaping.
See also
- Getting Started for a worked load-and-render example.
- Template Syntax for the markers in detail.
- Built-in Commands for the 14 commands shipped out of the box.
- Custom Commands for adding your own.