Stencil

Advanced template engine for Java

View project onGitHub

Template

Stencil templates are can be standalone or they can import and/or include one or more other templates.

Imports

A template can import all the macros, functions and variables from other templates using '$$import' syntax. Imports must be at the top of the file (only the parameter/block signature can precede it);

		$$import 'layout.st';
		
		$layout(title='My Page');
	

If macros, functions or variables from one template will conflict with another imported template. You can import a template with a prefix using an 'as' clause.

		$$import 'layout.st' as lay;
		
		$lay.layout(title='My Page');
	

Parameters and Blocks

A template can be treated as a macro itself by including a 'signature' as the first line of the template using the '$$() []' syntax

		$$(title) [header,footer];
		
		$header;
		
		$title - This template is also a macro!
		
		$footer;
	
You can then use the template with the '$include' output, including passing parameters and blocks.
		$include 'template.st' (title='Hello!')
			header {
				My Header
			}
			footer {
				My Footer
			};