Skip to content

Commit 972fd2b

Browse files
Makes README.md examples more convenient (#812)
1 parent 550d1da commit 972fd2b

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

README.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,14 @@ $ npm install mustache --save
3737
Below is a quick example how to use mustache.js:
3838

3939
```js
40-
var Mustache = require('mustache');
40+
const Mustache = require('mustache');
4141

42-
var view = {
42+
const view = {
4343
title: "Joe",
44-
calc: function () {
45-
return 2 + 4;
46-
}
44+
calc: () => ( 2 + 4 )
4745
};
4846

49-
var output = Mustache.render("{{title}} spends {{calc}}", view);
47+
const output = Mustache.render("{{title}} spends {{calc}}", view);
5048
```
5149

5250
In this example, the `Mustache.render` function takes two parameters: 1) the [mustache](http://mustache.github.io/) template and 2) a `view` object that contains the data and code needed to render the template.
@@ -65,8 +63,8 @@ If you need a template for a dynamic part in a static website, you can consider
6563
// file: render.js
6664

6765
function renderHello() {
68-
var template = document.getElementById('template').innerHTML;
69-
var rendered = Mustache.render(template, { name: 'Luke' });
66+
const template = document.getElementById('template').innerHTML;
67+
const rendered = Mustache.render(template, { name: 'Luke' });
7068
document.getElementById('target').innerHTML = rendered;
7169
}
7270
```
@@ -94,7 +92,7 @@ function renderHello() {
9492
fetch('template.mustache')
9593
.then((response) => response.text())
9694
.then((template) => {
97-
var rendered = Mustache.render(template, { name: 'Luke' });
95+
const rendered = Mustache.render(template, { name: 'Luke' });
9896
document.getElementById('target').innerHTML = rendered;
9997
});
10098
}
@@ -430,7 +428,7 @@ Custom delimiters can be used in place of `{{` and `}}` by setting the new value
430428
The `Mustache.tags` property holds an array consisting of the opening and closing tag values. Set custom values by passing a new array of tags to `render()`, which gets honored over the default values, or by overriding the `Mustache.tags` property itself:
431429

432430
```js
433-
var customTags = [ '<%', '%>' ];
431+
const customTags = [ '<%', '%>' ];
434432
```
435433

436434
##### Pass Value into Render Method

0 commit comments

Comments
 (0)