mustache

Can mustache iterate a top-level array?

给你一囗甜甜゛ 提交于 2019-11-28 03:05:14
My object looks like this: ['foo','bar','baz'] And I want to use a mustache template to produce from it something like this: "<ul><li>foo</li><li>bar</li><li>baz</li></ul>" But how? Do I really have to munge it into something like this first? {list:['foo','bar','baz']} You can do it like this... Mustache.render('<ul>{{#.}}<li>{{.}}</li>{{/.}}</ul>', ['foo','bar','baz']); It also works for things like this... var obj = [{name: 'foo'}, {name: 'bar'}]; var tmp = '<ul>{{#.}}<li>{{name}}</li>{{/.}}</ul>'; Mustache.render(tmp, obj); Andy Hull I had the same problem this morning and after a little

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

依然范特西╮ 提交于 2019-11-28 01:48:28
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 to write "<%"? Theoretically, I could use different tags, but I have too much code written using {{ and }} to change it all. Just change the delimiters temporarily: {{=<% %>=}} {{Look at the curlies!}} <%={{ }}=%> Assuming you are outputting HTML you could use an HTML entity to avoid it (mustache doesn't have any way to escape the opening tag built in). So to output {{ you would write {{ . To output <% you would write <% . You can use {{ by itself quite easily. If

How to parse mustache with Boost.Xpressive correctly?

只愿长相守 提交于 2019-11-27 23:22:25
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}} oder nicht{{/time}} <i>for all good men</i> to come to the {007} aid of their</bold> {{country}}.

Index of an array element in Mustache.js

大憨熊 提交于 2019-11-27 22:16:26
This is what I'd like to do in Mustache.js but not seeing how with the documentation. var view = {items:['Mercury','Venus','Earth','Mars']}; var template = "<ul> {{#items}}<li>{{i}} - {{.}}</li>{{/items}} </ul>"; var html = Mustache.to_html(template,view); Desired output: <ul> <li>0 - Mercury</li> <li>1 - Venus</li> <li>2 - Earth</li> <li>3 - Mars</li> </ul> An alternative solution, without fooling around with Mustache.js Instead of fooling around with mustache you might as well use a <ol></ol> instead of <ul></ul> , that will prefix each item with index+1 . If you'd like you can use css to

calling function with arguments in mustache javascript

懵懂的女人 提交于 2019-11-27 21:46:26
Is it possible to call a function with arguments with Mustache.js {{somefunction(somevalue)}} thank you Check out the section on Lambdas at http://mustache.github.com/mustache.5.html Mustache template block: {{#someFunction}}someValue{{/someFunction}} Function block: someFunction : function () { return function(val, render) { return "I passed in this value: " + render(val); }; } Output: I passed in this value: someValue If you want the script contents to be executed after the markup is inserted nito the dom you should use some library that will do the same like jquery. Try this out here: http:

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

放肆的年华 提交于 2019-11-27 19:02:27
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? You can switch delimiters to something that won't conflict with the triple mustaches, like erb-style tags: {{=<% %>=}} {{{ { "name": "<% name %>", "description": "<% description %>" } }}} {{{debug

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

丶灬走出姿态 提交于 2019-11-27 18:16:27
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].nodeType; jquery-1.9.0.js (line 3811) However, if I declare template as a plain text variable, it

Backbone.js Memory Management, Rising DOM Node Count

非 Y 不嫁゛ 提交于 2019-11-27 13:05:11
问题 Situation : I'm working on a pretty decently complex single page Backbone app that could potentially be running for 8-12+ hours straight. Because of this, there's a need to ensure that the application won't leak and have a reputation for crashing after X hours or slow down dramatically. The Application : The app is built on Backbone (mv*), Zepto (similar to jquery), Curl (amd loader) & Mustache (templating). Problem : I've just conquered the event listeners. The garbage collector seems to be

How to handle an IF STATEMENT in a Mustache template?

怎甘沉沦 提交于 2019-11-27 11:52:49
问题 I'm using mustache. I'm generating a list of notifications. A notification JSON object looks like: [{"id":1364,"read":true,"author_id":30,"author_name":"Mr A","author_photo":"image.jpg","story":"wants to connect","notified_type":"Friendship","action":"create"}] With mustache, how can I do a if statement or case statement based on the notified_type & action ... If notified_type == "Friendship" render ...... If notified_type == "Other && action == "invite" render..... How does that work? 回答1:

DOM tree based JavaScript template engines

回眸只為那壹抹淺笑 提交于 2019-11-27 11:29:23
问题 I am looking for a new Javascript template engine to replace old jQuery Template for my client side templating needs. I'd prefer approach where the template engine deals with DOM trees instead of text strings and later dumps the content of the cooked string into innerHTML . This is better performance wise and I find DOM manipulation more proper way of constructing more of DOM tree. What options I do have for Javascript template engine which would directly create DOM trees instead of being