Mustache template engine and mustache Template

Source: Internet
Author: User

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 :(


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.