|
|
{ "name": "mustache", "version": "0.7.2", "description": "Logic-less {{mustache}} templates with JavaScript", "author": { "name": "mustache.js Authors", "email": "http://github.com/janl/mustache.js" }, "keywords": [ "mustache", "template", "templates", "ejs" ], "main": "./mustache.js", "devDependencies": { "mocha": "1.5.0" }, "volo": { "url": "https://raw.github.com/janl/mustache.js/0.7.2/mustache.js" }, "scripts": { "test": "mocha test" }, "readme": "# mustache.js - Logic-less {{mustache}} templates with JavaScript\n\n> What could be more logical awesome than no logic at all?\n\n[mustache.js](http://github.com/janl/mustache.js) is an implementation of the [mustache](http://mustache.github.com/) template system in JavaScript.\n\n[Mustache](http://mustache.github.com/) is a logic-less template syntax. It can be used for HTML, config files, source code - anything. It works by expanding tags in a template using values provided in a hash or object.\n\nWe call it \"logic-less\" because there are no if statements, else clauses, or for loops. Instead there are only tags. Some tags are replaced with a value, some nothing, and others a series of values.\n\nFor a language-agnostic overview of mustache's template syntax, see the `mustache(5)` [manpage](http://mustache.github.com/mustache.5.html).\n\n## Where to use mustache.js?\n\nYou can use mustache.js to render mustache templates anywhere you can use JavaScript. This includes web browsers, server-side environments such as [node](http://nodejs.org/), and [CouchDB](http://couchdb.apache.org/) views.\n\nmustache.js ships with support for both the [CommonJS](http://www.commonjs.org/) module API and the [Asynchronous Module Definition](https://github.com/amdjs/amdjs-api/wiki/AMD) API, or AMD.\n\n## Who uses mustache.js?\n\nAn updated list of mustache.js users is kept [on the Github wiki](http://wiki.github.com/janl/mustache.js/beard-competition). Add yourself or your company if you use mustache.js!\n\n## Usage\n\nBelow is quick example how to use mustache.js:\n\n var view = {\n title: \"Joe\",\n calc: function () {\n return 2 + 4;\n }\n };\n\n var output = Mustache.render(\"{{title}} spends {{calc}}\", view);\n\nIn this example, the `Mustache.render` function takes two parameters: 1) the [mustache](http://mustache.github.com/) template and 2) a `view` object that contains the data and code needed to render the template.\n\n## Templates\n\nA [mustache](http://mustache.github.com/) template is a string that contains any number of mustache tags. Tags are indicated by the double mustaches that surround them. `{{person}}` is a tag, as is `{{#person}}`. In both examples we refer to `person` as the tag's key.\n\nThere are several types of tags available in mustache.js.\n\n### Variables\n\nThe most basic tag type is a simple variable. A `{{name}}` tag renders the value of the `name` key in the current context. If there is no such key, nothing is rendered.\n\nAll variables are HTML-escaped by default. If you want to render unescaped HTML, use the triple mustache: `{{{name}}}`. You can also use `&` to unescape a variable.\n\nView:\n\n {\n \"name\": \"Chris\",\n \"company\": \"<b>GitHub</b>\"\n }\n\nTemplate:\n\n * {{name}}\n * {{age}}\n * {{company}}\n * {{{company}}}\n * {{&company}}\n\nOutput:\n\n * Chris\n *\n * <b>GitHub</b>\n * <b>GitHub</b>\n * <b>GitHub</b>\n\nJavaScript's dot notation may be used to access keys that are properties of objects in a view.\n\nView:\n\n {\n \"name\": {\n \"first\": \"Michael\",\n \"last\": \"Jackson\"\n },\n \"age\": \"RIP\"\n }\n\nTemplate:\n\n * {{name.first}} {{name.last}}\n * {{age}}\n\nOutput:\n\n * Michael Jackson\n * RIP\n\n### Sections\n\nSections render blocks of text one or more times, depending on the value of the key in the current context.\n\nA section begins with a pound and ends with a slash. That is, `{{#person}}` begins a `person` section, while `{{/person}}` ends it. The text between the two tags is referred to as that section's \"block\".\n\nThe behavior of the section is determined by the value of the key.\n\n#### False Values or Empty Lists\n\nIf the `person` key does not exist, or exists and has a value of `null`, `undefined`, or `false`, or is an empty list, the block will not be rendered.\n\nView:\n\n {\n \"person\": false\n }\n\nTemplate:\n\n Shown.\n {{#person}}\n Never shown!\n {{/person}}\n\nOutput:\n\n "readmeFilename": "README.md", "_id": "mustache@0.7.2", "dist": { "shasum": "788c1e1f8af9c3c992ad5f6103aa3df7a029dfb7" }, "_from": "mustache" }
|