Mustache

Mustache語法記錄

Mustache的類型

  • {{data}}
  • {{#data}} {{/data}}
  • {{^data}} {{/data}}
  • {{.}}
  • {{>partials}}
  • {{{data}}}、{{&}}
  • {{!comments}}
  • {{= =}}

Mustache類型詳解

  • {{data}}

    用于傳入變量值

    input:
    data = “123”
    
    mustache temlate:
    {{data}}
    
    generator file content:
    123
    
  • {{#data}} {{/data}}: section【true、false、list】

    用于遍歷傳入值,類似數(shù)組for循環(huán),為空則不展示該塊內(nèi)容;數(shù)組內(nèi)部一般是鍵值對

    input:
    data = [{"name":"peter"},{"name":"tiny"}]
    
    mustache temlate:
    {{#data}}
    hellow {{name}}
    {{/data}}
    
    generator file content:
    hello peter
    hello tiny
    
  • {{^data}} {{/data}}

    與{{#data}} 相反,成對存在相當(dāng)于if-else

    input:
    {  "persons": [] }
    
    mustache temlate:
    {{#persons}}
      <b>{{name}}</b>
    {{/persons}}
    {{^persons}}
      No person.
    {{/persons}}
    
    generator file content:
    No person.
    
  • {{.}}

    表示枚舉,遍歷某個變量,單純的數(shù)組

    input:
    names: ['Bill', 'Tom', 'Alan']
    
    mustache temlate:
    {{#names}}{{.}}。{{/names}}
    
    generator file content:
    Bill。Tom。Alan。
    
  • {{<partials}}

    input:
    {
        "name": Iface
        "methods":[
            "name": "m1",
            "name": "m2",
            "name": "m3",
        ]
    }
    
    mustache temlate:
    
    1. interface.mustache:
    public interface {{name}} {
    {{#methods}}
      {{> method}}
    {{/methods}}
    }
    
    2. method.mustache:
    public void {{name}}();
    
    generator file content:
    public interface Iface {
        public void m1();
        public void m2();
        public void m3();
    }
    
  • {{{data}}}、{{&}}

    和{{data}}類似,都是傳入變量用來顯示,但是內(nèi)部內(nèi)容顯示的是 已轉(zhuǎn)碼(unescape)的,直接顯示對應(yīng)符號,而不是符號對應(yīng)的編碼值

    input:
    {"name":"<b>world</b>"}
    
    mustache temlate:
    hello, {{name}}!
    hello, {{{name}}}!
    
    generator file content:
    hello, &lt;b&gt;world&lt;/b&gt!
    hello, <b>world</b>!
    
  • {{!comments}}

    注釋、描述

    input:
    {"name":"<b>world</b>"}
    
    mustache temlate:
    Hello{{! comment }}.
    
    generator file content:
    Hello.
    
  • {{= =}}

    修改定界符,默認{{}}為定界符

    {{=<% %>=}} -> <% %>
    <%={{ }}=%> -> {{}}
    
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Getting Started Use the Current Stable Version (7.1) Buil...
    Leonzai閱讀 2,051評論 0 3
  • Mustache 是一款經(jīng)典的前端模板引擎,在前后端分離的技術(shù)架構(gòu)下面,前端模板引擎是一種可以被考慮的技術(shù)選型,隨...
    __ee47閱讀 705評論 0 0
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,502評論 19 139
  • Spring Boot 參考指南 介紹 轉(zhuǎn)載自:https://www.gitbook.com/book/qbgb...
    毛宇鵬閱讀 47,253評論 6 342
  • 概要 64學(xué)時 3.5學(xué)分 章節(jié)安排 電子商務(wù)網(wǎng)站概況 HTML5+CSS3 JavaScript Node 電子...
    阿啊阿吖丁閱讀 9,789評論 0 3

友情鏈接更多精彩內(nèi)容