mustache模板引擎,mustache模板

來源:互聯網
上載者:User

mustache模板引擎,mustache模板

Logic-less templates.

github:http://mustache.github.com/ 
文檔:http://mustache.github.com/mustache.5.html 

http://mustache.github.io

Java 版 Mustache SVN 源碼 
http://jmustache.googlecode.com/svn   

mustache 類似  freemark和valicity 模板引擎,不過mustache 更輕量級,支援語言: Ruby, JavaScript, Python,Erlang, 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

 mustache 支援功能比較弱,不過我們可以建立在mustache 之上進行擴充實現。

mustache的特點就是很文法很簡單,主要文法如下

  • {{ name }} 列印變數,預設是escape過的,如果不要escape,用3個分隔字元 {{{ name }}},或者用 {{ &name }},這個和分隔字元無關
  • {{#person}}…{{/person}} 區塊,4種方式
    • person是真假值,決定是否輸出
    • person 是list of array,會迴圈展開 for x in person:section.render('xxx)
    • person 是匿名函數/object, 區塊包裹的html 會作為參數傳遞進去
    • person 是dict,直接列印 dict[key]
  • {{^person}}…{{/person},反向區塊
  • {{!name }} 注釋
  • {{> box }} 載入子模組

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


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.