Mustache template engine and mustache Template
Logic-less templates.
Github: http://mustache.github.com/
Document: http://mustache.github.com/mustache.5.html
Http://mustache.github.io
Java version Mustache SVN source code
Http://jmustache.googlecode.com/svn
Mustache is similar to freemark and valicity template engine. However, mustache is more lightweight and supports the following languages: Ruby, JavaScript, Python, Erlang, and node. js, PHP, Perl, Perl6, Objective-C, Java, C #/. NET, Android, C ++, Go, Lua, ooc, ActionScript, ColdFusion, Scala, Clojure, Fantom, CoffeeScript, D, Haskell, XQuery, ASP, Io, Dart, Haxe, delphi, Racket, Rust, OCaml, Swift, and for Bash
The mustache support function is relatively weak, but we can implement it based on the mustache.
The mustache syntax is very simple. The main syntax is as follows:
- The variables are printed by {name}. The default value is escape. If you do not want escape, use three delimiters: {name} or {& name }}, this is irrelevant to the separator.
- {{# Person }}... {/Person} block, in four ways
- Person is a false value and determines whether to output
- Person is list of array and will be expanded cyclically for x in person: section. render ('xxx)
- The person is an anonymous function/object, and the html of the block package is passed as a parameter.
- The person is dict and the dict [key] is printed directly.
- {^ Person }}... {/Person}, reverse block
- {{! Name} Comment
- {> Box} load sub-module
Template:
{{#person?}} Hi {{name}}!{{/person?}}
Hash:
{ "person?": { "name": "Jon" }}
Output:
Hi Jon!
Template:
{{#repo}} <b>{{name}}</b>{{/repo}}{{^repo}} No repos :({{/repo}}
Hash:
{ "repo": []}
Output:
No repos :(