arc-templates
Version:
Fully powered JavaScript template engine with halfway-decent syntax.
56 lines (28 loc) • 2.01 kB
Markdown
# arc-templates
Fully powered ES6 JavaScript template engine with halfway-decent syntax.
[](http://badge.fury.io/gh/StephenCleary%2Farc-templates) [](https://travis-ci.org/StephenCleary/arc-templates)
[](https://david-dm.org/StephenCleary/arc-templates) [](https://david-dm.org/StephenCleary/arc-templates#info=devDependencies)
There are two "builds" available: a Node.js 4+ version with minimal Babel transpiling, and an ES5 version with full Babel transpiling. The unit tests are run on both new and older Node versions.
# Simple example
Templates can use [expressions](doc/expressions.md):
Hello, ${ name }
with a data object of `{ name: 'world' }` will result in:
Hello, world
# Loops
[JavaScript blocks](doc/language.md) with nested [document blocks](doc/document.md) allow a natural expression of loops:
<% for (let item of items) { <:<div>${item}</div>:> } %>
# Layouts
Templates can define [layouts](doc/layout.md) for a "template of the template":
<! layout.html !><div>body</div>
If `layout.html` contains:
<html><head></head><body><**></body></html>
Then the final result is:
<html><head></head><body><div>body</div></body></html>
Templates can also define [multiple named blocks](doc/layout.md) for use by the layout template; for example, separate sections for the `head` and `body` in an HTML document.
# Partials
Templates can also [include other templates](doc/partials.md) in their output:
before <( include.html )> after
If `include.html` contains:
middle
Then the final result is:
before middle after