mustache

What are the differences between Mustache.js and Handlebars.js?

白昼怎懂夜的黑 提交于 2019-11-27 09:57:29
Major differences I've seen are: Handlebars adds #if , #unless , #with , and #each Handlebars adds helpers Handlebars templates are compiled (Mustache can be too) Handlebars supports paths Allows use of {{this}} in blocks (which outputs the current item's string value) Handlebars.SafeString() (and maybe some other methods) Handlebars is 2 to 7 times faster Mustache supports inverted sections (i.e. if !x ... ) (Please correct me if I'm wrong with the above.) Are there any other major differences I am missing? frontendbeauty You've pretty much nailed it, however Mustache templates can also be

Handlebars Template rendering template as text

佐手、 提交于 2019-11-27 07:44:35
I created a helper in Handlebars to help with logic, but my template parses the returned html as text rather than html. I have a quiz results page that is rendered after the quiz is completed: <script id="quiz-result" type="text/x-handlebars-template"> {{#each rounds}} {{round_end_result}} {{/each}} <div class="clear"></div> </script> For each of the rounds, I use a helper to determine which template to render a round's result: Handlebars.registerHelper("round_end_result", function() { if (this.correct) { var source = ''; if (this.guess == this.correct) { console.log("correct guess"); var

What's the advantage of Logic-less template (such as mustache)?

孤者浪人 提交于 2019-11-27 05:57:39
Recently, I ran into mustache which is claimed to be Logic-less template . However, there is no explaining why it is designed in Logic-less way. In another word, what's the advantage of Logic-less template? In other words, it prevents you from shooting yourself in the foot. In the old JSP days, it was very common to have JSP files sprinkled with Java code, which made refactoring much harder, since you had your code scattered. If you prevent logic in templates by design (like mustache does), you will be obliged to put the logic elsewhere, so your templates will end up uncluttered. Another

Writing a helper that produces bound results?

一笑奈何 提交于 2019-11-27 02:43:03
问题 I have a date/time formatting helper but what it produces does not update when the underlying property changes. This is not a surprise, but does anyone know how to produce bindings in helpers? I invoke the helper like this... {{timestamp created_at}} ...and here is the helper itself: Handlebars.registerHelper('timestamp', function(context, options) { var formatter = options.hash['format'] ? options.hash['format'] : 'hh:mm a MM-DD-YYYY'; var original_date = Ember.getPath(this, context); //

Check with mustache js if parameter is a specific value

僤鯓⒐⒋嵵緔 提交于 2019-11-27 01:51:10
问题 Is it possible to check in mustache js for a specific value like {{name}} == "James" ? DATA: json: { name: "James" } HTML: {{name}} //Will give me James as output {{name == "James" }} //Is it possible to check specific value? 回答1: No. The idea behind mustache is that it is a logic-less templating syntax. So, no, such a logic is not possible. We call it "logic-less" because there are no if statements, else clauses, or for loops. Instead there are only tags. Some tags are replaced with a value,

How to parse mustache with Boost.Xpressive correctly?

谁都会走 提交于 2019-11-26 23:18:16
问题 I have tried to write a mustache parser with the excellent Boost.XPressive from the brilliant Eric Niebler . But since this is my first parser I am not familiar with the "normal" approach and lingo of compiler writers and feel a bit lost after a few days of trial&error. So I come here and hope someone can tell me the foolishness of my n00bish ways ;) This is the HTML code with the mustache templates that I want to extract (http://mustache.github.io/): Now <bold>is the {{#time}}gugus {{zeit}}

templateSettings not working

妖精的绣舞 提交于 2019-11-26 23:17:41
问题 I get a compilation error at runtime when I attempt to render the following template: <script id="tmpl-books" type="text/template"> <% _.each(items, function(item) { %> <ul> <li>Title: <%= item.title %></li> <li>Author: <%= item.author %></li> </ul> <% }); %> </script> <script type="text/javascript"> _.templateSettings = { evaluate: /\{\{=(.+?)\}\}/g, interpolate: /\{\{(.+?)\}\}/g, escape: /\{\{-(.+?)\}\}/g }; var list = { items: [ { "title": "Myst: The Book of Atrus", "author": "Rand Miller"

Escape double braces {{ … }} in Mustache template. (templating a template in NodeJS)

别来无恙 提交于 2019-11-26 22:45:24
问题 I'm trying to template a template, like below: {{{ { "name" : "{{name}}", "description" : "{{description}}" } }}} {{{debug this}}} <h1>{{name}}</h1> Where I want to triple brackets to stay, but double brackets to be replaced with the JSON passed in. Anyone know the best way to do this without writing post-process JS code, and if not, is there a good nodeJS template engine for this type of scenario? 回答1: You can switch delimiters to something that won't conflict with the triple mustaches, like

jQuery + client-side template = “Syntax error, unrecognized expression”

浪子不回头ぞ 提交于 2019-11-26 22:39:52
问题 I just updated jQuery from 1.8.3 to 1.9, and it started crashing all of a sudden. This is my template: <script type="text/template" id="modal_template"> <div>hello</div> </script> This is how I read it: modal_template_html = $("#modal_template").html(); This is how I transform it into jQuery object (I need to use jQuery methods on it): template = $(modal_template_html); ... and jQuery crashes! Error: Syntax error, unrecognized expression: <div>hello</div> slice.call( docElem.childNodes, 0 )[0

In Mustache templating is there an elegant way of expressing a comma separated list without the trailing comma?

旧城冷巷雨未停 提交于 2019-11-26 22:35:27
问题 I am using the Mustache templating library and trying to generate a comma separated list without a trailing comma, e.g. red, green, blue Creating a list with the trailing comma is straightforward, given the structure { "items": [ {"name": "red"}, {"name": "green"}, {"name": "blue"} ] } and the template {{#items}}{{name}}, {{/items}} this will resolve to red, green, blue, However I cannot see an elegant way of expressing the case without the trailing comma. I can always generate the list in