Stencil

Advanced template engine for Java

View project onGitHub

Stencil is a delightful template language with a concise syntax and advanced capabilities. It is written in Java and has an easy and advanced API that makes integrating it into any environment a breeze.

Introduction

Stencil uses '$' to begin dynamic outputs and ';' to end them. It allows you to quickly define macros and functions right inside your template. Layouts, even extremely advanced ones, are supported by using the same simple and elegant block passing syntax that is used with macros. Even whole templates files can be used as macros or layouts. To wrap it all up nicely Stencil is built around a simple expression language that can be used in any of its contexts.

Stencil also features a rich API that allows advanced control of loading, caching and makes extending the engine easy. It even has some really nifty features like Extension Methods that save a lot of time when writing templates.

Example

index.st

$$import 'layout.st'

$**
 * Use our layout macro from 'layout.st'
 **$

$layout('My Page')
	header {
		<h1>Welcome</h1>
	}
	content {
		Glad you stopped by this page!
	};

layout.st

$**
 * Define a simple layout macro
 **$
$macro layout(title) [header, content, footer] {
<html>
<head>
	<title>$title;</title>
</head>
<body>
	<header>
		$header;
	</header>
	<div class="content">
		$content;
	</div>
	<footer>
		$footer {
			© Copyrright 2003
		};
	</footer>
</body>
};