How does one use a literal {{ in a Mustache template?

前端 未结 4 721
星月不相逢
星月不相逢 2020-12-07 00:16

How does one use a literal \"{{\" in a Mustache template?

On a side note, if I\'m using custom tags, like <% and %>, is there a way

4条回答
  •  无人及你
    2020-12-07 01:01

    You can use {{ by itself quite easily. If you are trying to document something like {{example}} you could always pass in the first two cur lies with your data.

    orphaned curlies are easy {{ 
    {{curly}}example}} curlies are harder

    Some simple rendering:

    var data = { 'curly' : '{{'},
        tpl = $('#curly').html(),
        html = Mustache.to_html(tpl, data);
    
    document.write(html);​
    

    Results in:

    orphaned curlies are easy {{ 
    {{example}} curlies are harder
    

    Here's the full working jsFiddle

提交回复
热议问题