mustache-layout
A mustache template engine with layout architecture
Features
- All Mustache features like
- Partials
- Fors
- Functions
- Express 3.x/4.x support
A Simple example
Looping cart product items
cart-items.html
{{#cartItems}}
{{> sidebar/cart-item }}
{{/cartItems}}
controller.js
app.get("/cart", function(req, res) {
res.render("cartItems", {
cartItems: [
{
name: "Tommy Hilfiger",
description: "Combining contrast brand name printed on the front ...",
price: 9.98,
quantity: 3
},{
name: "TOPMAN",
description: "Classic fit",
price: 15.98,
quantity: 5
}
],
});
});
Other samples
-
Visit demo folder and run the express sample
npm install && npm start
then visit the demo -
creating your own demo
var app = ;// here express configurations...var mustacheLayout = ;app;app;app;app;app;app;app;app;
Escaping template tags
On versions 1.0.6
and bellow, all the mustache templates are compiled on serverside, it means that if you have a
template tag inside .html
it will be compiled, now it not occurs
Observations
-
Make sure that every template have a id, or unique attribute to be different of others templates
-
wrong examples
<script type="text/template" class="xyz"></script> <script type="text/template" class="xyz"></script>
-
right examples
<script type="text/template" class="xyz"></script> <script type="text/template" class="xyz2"></script>
-
-
Ever, use
type="text/template"
view options
set escapeTemplate
to false
If for some motive you want to do not it, on License
This project is released under version 2.0 of the Apache License.
Please say me if it works for you contacting edigitalb@gmail.com
or creating suggestions and defects