https://github.com/mageddo/mustache-layout
A mustache template engine with layout architecture
https://github.com/mageddo/mustache-layout
Last synced: about 1 year ago
JSON representation
A mustache template engine with layout architecture
- Host: GitHub
- URL: https://github.com/mageddo/mustache-layout
- Owner: mageddo
- Created: 2015-10-04T21:06:13.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-12-05T14:12:45.000Z (over 9 years ago)
- Last Synced: 2025-03-04T06:47:55.978Z (over 1 year ago)
- Language: JavaScript
- Size: 24.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# mustache-layout
A mustache template engine with layout architecture
# Features
* All [Mustache ](http://mustache.github.io) features like
* Partials
* Fors
* Functions
* Express 3.x/4.x support
# A Simple example
Looping cart product items
cart-items.html
- {{name}} - {{price}}
{{#cartItems}}
{{/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](http://localhost:3003)
* [Download the project demo](https://github.com/mageddo/mustache-layout-demo)
* creating your own demo
```javascript
var app = require("express");
// here express configurations
...
var mustacheLayout = require("mustache-layout");
app.locals({
"title": "Demo mustache layout with express"
});
app.set('views', './view');
app.set('view engine', 'html');
app.set("view options", {layout: true});
app.engine("html", mustacheLayout);
app.get("/withCustomLayout", function(req, res) {
res.render("myView", {
aVariable: "helloWorld",
layout: "myCustomLayout"
});
});
app.get("/withoutLayout", function(req, res) {
res.render("myView", {
aVariable: "helloWorld",
layout: false
});
});
app.get("/withDefaultLayout", function(req, res) {
res.render("myView", {
aVariable: "helloWorld"
});
});
```
# 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
* right examples
* Ever, use `type="text/template"`
## If for some motive you want to do not it, on `view options` set `escapeTemplate` to `false`
# License
This project is released under version 2.0 of the [Apache License][].
[Apache License]: http://www.apache.org/licenses/LICENSE-2.0
**Please** say me if it works for you contacting `edigitalb@gmail.com` or [creating suggestions and defects](https://github.com/mageddo/mustache-layout/issues)