mustache

How is internationalization configured for Hogan.js?

六眼飞鱼酱① 提交于 2019-12-01 21:46:48
I'm looking to use hogan.js to create html form a template in the browser. I've read that hogan supports i18n, but I can't find an example of how this works. How do you pass the translated text to hogan and what tag do you put in the template, I have seen both {{_i}} and {{i18n}}? It would seem I was confusing an older fork of Mustache.js from Twitter, with Hogan a separate mustache compiler from also from twitter. The fork does support an {{_i}} tag for internationalization. This will then call a global function with the name _ in which you provide you're own method for looking up the

Mustache - how can I do something *once* for an iterable?

纵然是瞬间 提交于 2019-12-01 20:42:32
Say I have a user , who has many items How can I have a single 'Sweet, you have items!', provided there's at last one item in items ? {{#user.items}} Sweet, you have items! {{/user.items}} Note : I know I can create a section that will repeat for each item. But right now I don't want to do that. The answer (like most things Mustache) is "prepare your view model before rendering" :) But if you're not into that, you can usually fake it in Mustache.js like this: {{# user.items.0 }} Sweet, you have items! {{/ user.items.0 }} (The more Mustachey way would be to add a hasItems property or function

How to Iterate over a hash in mustache.js

倾然丶 夕夏残阳落幕 提交于 2019-12-01 17:56:32
Given this hash a = { foo : { ... }, bar : { ... }, zap : { ... } } i want to iterate over it but since the keys are different I am not sure how to in Mustache.js the output will look something like this foo : (contents here) If you know the key in the nested object that you're trying to retrieve, you can use a function. see: http://jsfiddle.net/jimschubert/zPWDJ/ js: $(function() { var names = { "a": [ {"foo": { "name": "foo name"}}, {"bar": { "name": "bar name"}}, {"zap": { "name": "zap name"}} ], "n": function() { var self = this; var n = ""; Object.keys(self).forEach(function(k, v) { if

How to Iterate over a hash in mustache.js

孤街浪徒 提交于 2019-12-01 17:48:21
问题 Given this hash a = { foo : { ... }, bar : { ... }, zap : { ... } } i want to iterate over it but since the keys are different I am not sure how to in Mustache.js the output will look something like this foo : (contents here) 回答1: If you know the key in the nested object that you're trying to retrieve, you can use a function. see: http://jsfiddle.net/jimschubert/zPWDJ/ js: $(function() { var names = { "a": [ {"foo": { "name": "foo name"}}, {"bar": { "name": "bar name"}}, {"zap": { "name":

Node.js + Express - How to get Mustache partials working?

╄→尐↘猪︶ㄣ 提交于 2019-12-01 17:43:39
I'm trying to get Mustache working properly with Express, and as one can guess, I'm having troubles. The following line initializes Mustache nice and clean. Variables render as expected. app.register('html', require(__dirname+'/public/js/libs/mustache.js')); However, the problems start to rise when partials are thrown in the mix. With Mustache, this here partial should invoke header view/partial. {{> header}} But alas, nothing happens. :/ Even when I offer the partial directly, Mustache fails to render it. app.get('/', function(req, res) { res.render('welcome', { partials: { header: '<h1

add mustache temple to require in require.js AMD

怎甘沉沦 提交于 2019-12-01 13:48:17
In js you can load a html template in the require part while defining a module. For example: template file : test.html <script id="test" type="text/template"> <div class="q-header-holder"> <h1> {{ quizName }}</h1> <a href="{{ instructionLinks }}" class="q-instruction-btn">Instructions</a> </div> </script> in module define( ["template/test"], function() { //.. rest of code .. } ); But this throws error while fetching the file the filename appended with .js extension. Is there any way to include the template in the define block? Yep, use the text plugin - http://requirejs.org/docs/download.html

How do I reference a field name that contains a dot in mustache template?

半世苍凉 提交于 2019-12-01 05:28:42
How do I reference a field name that contains a dot in mustache template? For instance, if I have a view like { "foo.bar": "my value" } then how can I put my value into a template? Using {{foo.bar}} doesn't work because mustache thinks the dot is part of the path, like there should be a "foo" that has a "bar". Will Klein You can't read a key with a . in it from Mustache. The Mustache spec dictates that . is used to split content names. Mustache provides a means of escaping but only for HTML content. Mustache spec: interpolation You will need to pre-process your data to make it usable in a

Mustache.js: Iterate over a list received via json [duplicate]

故事扮演 提交于 2019-12-01 03:52:24
Possible Duplicate: Mustache JS Template with JSON Collection I have a json response like this that I want to use with Mustache.js: [ {"id": "1", "details": {"name": "X", "type":"Y" }}, {"id": "2", "details": {"name": "aName", "type":"something" }} ] How do I iterate over this using mustache.js? The array itself should be a value in a bigger Object, like so: var obj = { arr: [ {"id": "1", "details": {"name": "X", "type":"Y" }}, {"id": "2", "details": {"name": "aName", "type":"something" }} ] } Then you can do: {{#arr}} my id: {{id}} {{/arr}} the use for {{#bla}} is actually overloaded. When

Loading handlebars.js template from external html file shows nothing

↘锁芯ラ 提交于 2019-12-01 00:51:29
This question is a bit of a stretch of my JS skills, so I might explain it like an idiot. Here is my JavaScript to get the json from the server, and try to push it into a template: //Server Interface Start //Access the web api for The User: var lucidServer = (function () { //global error handler $(document).ajaxError(function (event, xhr) { alert(xhr.status + " : " + xhr.statusText); }); //client Calls var getClients = function (id) { return $.ajax(clientUrl + "/list/" + id) }; var getClient = function (id) { return $.ajax(clientUrl + "/details/" + id) }; //push them out to the world! return {

Using mustache to fill in a html tag argument

匆匆过客 提交于 2019-11-30 23:46:40
I'm trying the append an identier (id) to the href below using mustache Template: <div id='tmpl'> <a href='#product_detail?'{{id}}>link</a> </div> var template = $('#tmpl').html(); Data: var model = { id: 22 }; Rendering the template using the model data: var html = Mustache.to_html(template, model); results in: <a href="#product_detail?%7B%7Bid%7D%7D">link</a> If the template is changed to: <div id='tmpl'> <a href='#product_detail?'{{id}}>link</a> </div> The resulting template is: <a href="#product_detail?" 0="">link</a> The 'problem' seems to be that jQuery is changing the single quotes in