mustache

Mustache JS Templating - How do I embed a variable in a script tag string?

孤人 提交于 2019-11-30 19:12:42
I just started using Mustache and I like it so far, but this has me perplexed. I am using the GitHub gist API to pull down my gists, and part of what I want to do is include the embedding functionality into my page. The problem is Mustache seems to not want to have anything to do with my dynamic script tag. For example, this works fine: <div class="gist-detail"> {{id}} <!-- This produces a valid Gist ID --> </div> Additionally, this works perfect: <div class="gist-detail"> <script src='http://gist.github.com/1.js'></script> <!-- Produces the correct embed markup with Gist ID #1 --> </div> If I

前端技术之:常见的前端页面模板库

倾然丶 夕夏残阳落幕 提交于 2019-11-30 17:59:48
VueJs https://cn.vuejs.org/ https://github.com/vuejs/vue React https://reactjs.org/ Handlebars http://handlebarsjs.com/ https://github.com/wycats/handlebars.js Mustache https://mustache.github.io/ Ejs https://github.com/tj/ejs ArtTemplate http://aui.github.io/art-template/zh-cn/ https://github.com/aui/art-template Jade/Pug http://jade-lang.com/ https://pugjs.org NunJucsks https://mozilla.github.io/nunjucks/ Template7 Template7 is a mobile-first JavaScript template engine with Handlebars-like syntax. https://framework7.io/docs/template7.html UnderscoreJs Template https://underscorejs.org/

iterate through JSON array with mustache

元气小坏坏 提交于 2019-11-30 17:37:32
I am new to Mustache, please bear with me :) I have an array in my JSON "prop":{"brands":["nike","adidas","puma"]} if I have the template like this {{#prop}} <b>{{brands}}</b> {{prop}} and I want to get something like: <b>nike</b> <b>adidas</b> <b>puma</b> I understand the elements in the array are not hash key-value pairs, however I am wondering if there is anyway in mustache that I can iterate through the elements. Thanks! mustache is logicless, so writing your own iteration/loop in it is impossible. It is easy to convert your JSON though. For example: var json = '{"prop":{"brands":["nike",

Mustache and Haml

扶醉桌前 提交于 2019-11-30 14:14:43
问题 I have got this haml/mustache template: {{#data}} ok {{#items}} {{#item}} %b ID: {{id}} {{/item}} {{/items}} {{/data}} And I have got Illegal nesting: nesting within plain text is illegal Error. I render it in Sinatra Mustache.render(haml(:index), hash) 回答1: I'm not sure about rendering with Sinatra, but with this command: cat example.yml foo.haml.mustache | mustache | haml -e this data file example.yml --- data: - items: - item: - id: 1 - id: 2 - id: 3 --- and template (foo.haml.mustache ):

only show the first item in list using Mustache

泪湿孤枕 提交于 2019-11-30 13:45:39
问题 I am using the mustache template engine and I only want to display the first item in a long list but cant seem to find the docs for doing so? if I use: {{# links}}<a href="{{& url}}">{{& title }}</a>{{/ links}} i get all of the links, however i only want the first one to be displayed, sounds easy but I cant find any docs on this. 回答1: This solution is working with the new version of Mustache.js ( only ): mustache.render("{{a.0}}", {a: ['hi','world']}) => 'hi' 回答2: The solution @Millad

How do I use nested iterators with Mustache.js or Handlebars.js?

江枫思渺然 提交于 2019-11-30 10:46:06
问题 I would like to use handlebars.js or mustache.js to iterate over a list of families, and then iterate over that family's members. Inside of both loops, I want to display properties of both. However, once I get into the second iteration, none of the family variables are visible. {{#each families}} {{#each members}} <p>{{ ( here I want a family name property ) }}</p> <p>{{ ( here I want a member name property ) }}</p> {{/each}} {{/each}} Is this possible? I'd greatly appreciate any help! 回答1:

Mustache and Haml

会有一股神秘感。 提交于 2019-11-30 09:54:46
I have got this haml/mustache template: {{#data}} ok {{#items}} {{#item}} %b ID: {{id}} {{/item}} {{/items}} {{/data}} And I have got Illegal nesting: nesting within plain text is illegal Error. I render it in Sinatra Mustache.render(haml(:index), hash) I'm not sure about rendering with Sinatra, but with this command: cat example.yml foo.haml.mustache | mustache | haml -e this data file example.yml --- data: - items: - item: - id: 1 - id: 2 - id: 3 --- and template (foo.haml.mustache ): {{#data}} #ok {{#items}} {{#item}} %b ID: {{id}} {{/item}} {{/items}} {{/data}} I get following result: <div

JSON Object into Mustache.js Table

谁说胖子不能爱 提交于 2019-11-30 05:21:42
问题 I'm trying to create a table with a JSON Object using Mustache.js. I wanted it to show two rows, however it's only showing the second row only. I suspect that the first row is being overwritten by the second when it's being bound again in the loop. How do I work my way around it? Or is there a better structure I should follow? Javascript: var text = '[{"Fullname":"John", "WorkEmail":"john@gmail.com"},{"Fullname":"Mary", "WorkEmail":"mary@gmail.com"}]' var obj = JSON.parse(text); $(document)

How to set a selected value in a dropdown list using Mustache.js?

浪子不回头ぞ 提交于 2019-11-30 04:42:37
Is it possible to do this with Mustache.js? var data = {"val":"3"}, template = '<select>' + '<option value="1">1</option>' + '<option value="2">2</option>' + '<option value="3">3</option>' + '</select>'; var html = Mustache.to_html(template, data); $(html).appendTo('body'); The val attribute doesn't work, because a <select> takes its value from the <option> s which have the selected attribute. I'm not very familar with Mustache, but this should work: // snip... var html = Mustache.to_html(template, data); $(html) .find('option[value=3]').attr('selected', true) .end().appendTo('body'); I think

Mustache JS Templating - How do I embed a variable in a script tag string?

拜拜、爱过 提交于 2019-11-30 03:55:36
问题 I just started using Mustache and I like it so far, but this has me perplexed. I am using the GitHub gist API to pull down my gists, and part of what I want to do is include the embedding functionality into my page. The problem is Mustache seems to not want to have anything to do with my dynamic script tag. For example, this works fine: <div class="gist-detail"> {{id}} <!-- This produces a valid Gist ID --> </div> Additionally, this works perfect: <div class="gist-detail"> <script src='http:/