In this section you will learn how to reuse Mustache templates in Handlebars.java
A partial is a template that can be included into other template. Syntax is as follow:
header.hbs:
footer.hbs:
<span>Powered by Handlebars.java</span>
home.hbs:
{{> header}} <p>Home page</p> {{> footer}}
Output:
<h1>Title</h1> <p>Home page</p> <span>Powered by Handlebars.java</span>
Partials begin with a greater than sign, like {{> box}}.
Partials are rendered at runtime (as opposed to compile time), so recursive partials are possible. Just avoid infinite loops.
Template inheritance can be done with block/partial syntax
.
base.hbs:
{{#block "header"}} <h1>Title</h1> {{/block}} {{#block "content"}} {{/block}} {{#block "footer" }} <span>Powered by Handlebars.java</span> {{/block}}
home.hbs:
{{#partial "content" }} <p>Home page</p> {{/partial}} {{> base}}
Output:
<h1>Title</h1> <p>Home page</p> <span>Powered by Handlebars.java</span>
Thank you, for reading the Handlebars.java blog.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4