mustache

Mustache Template with Nested Array of Objects

自作多情 提交于 2019-12-21 02:34:10
问题 Could use a little help figuring out why my Mustache template isn't rendering properly. I'm very confused why the following isn't working. I'm sure it's a minor stupid mistake of mine or something... var tableRows = [ {name: 'name1', values: ['1','2','3']}, {name: 'name2', values: ['1','2','3']}, {name: 'name3', values: ['1','2','3']} ]; var template = $('#mustache-template').html(); $('#target').append(Mustache.render(template, {rows: tableRows})); HTML Template: <div id="mustache-template">

Django and Mustache use the same syntax for template

浪子不回头ぞ 提交于 2019-12-20 09:49:00
问题 I try to smuggle HTML template in the HTML for mustache.js, however the django template engine remove all the placeholders that should be output as-is to the front-end The template is included in HTML in this way: <script type="text/x-mustache-template" data-id="header_user_info"> <div id="header_user_info"> <div id="notification">0</div> <a href="#">{{username}}</a> </div> </script> and I can get the HTML template by running $(el).html(), and generate html by using Mustache.to_html(temp,

How to make i18n with Handlebars.js (mustache templates)?

孤街浪徒 提交于 2019-12-20 08:26:12
问题 I'm currently using Handlebars.js (associated with Backbone and jQuery) to make a web app almost totally client side rendered, and I'm having issues with the internationalisation of this app. How can I make this work? Are there any plugins? 回答1: I know this has been answered, but I'd like to share my simple solution. To build on Gazler's solution using I18n.js (which we use with our project at work), I just used a very simple Handlebars helper to facilitate the process to do the localization

Dynamically loading webpage using node/express, need to render on the same page

无人久伴 提交于 2019-12-20 06:37:54
问题 I'm using node and express with the mustache templating system, I have created a multipage website but don't want it refresh on rendering (make it single page), what can i do to solve this? i think i need to use ajax, i'm just not sure how. right now it is rendering the url on to another page, but i need it to render on the same page. this is some of the code const express = require('express'); const parseurl = require('parseurl'); const bodyParser = require('body-Parser'); const path =

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

梦想的初衷 提交于 2019-12-19 05:59:07
问题 This question already has answers here : Closed 7 years ago . 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? 回答1: The array itself should be a value in a bigger Object, like so: var obj = { arr: [ {"id": "1", "details": {"name": "X", "type":"Y" }}

Loading handlebars.js template from external html file shows nothing

谁说胖子不能爱 提交于 2019-12-19 04:43:02
问题 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

Using mustache to fill in a html tag argument

三世轮回 提交于 2019-12-19 04:05: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="

Access Nested Backbone Model Attributes from Mustache Template

纵饮孤独 提交于 2019-12-18 11:38:20
问题 I have one Backbone model which has an attribute that is a reference to another Backbone model. For example, a Person has a reference to an Address object. Person FirstName LastName Address Street City State Zip These are classes that extend the Backbone model. So, then if I construct an object like the following... var address = new Address({ Street: "123 Main", City: "Austin" }); var person = new Person({ FirstName: "John", Address: address }); I cannot seem to figure out how to access it

mustache语法

我与影子孤独终老i 提交于 2019-12-18 11:28:54
Mustache 是一款经典的前端模板引擎,在前后端分离的技术架构下面,前端模板引擎是一种可以被考虑的技术选型,随着重型框架(AngularJS、ReactJS、Vue)的流行,前端的模板技术已经成为了某种形式上的标配 变量 {{person}} 带有HTML的变量 {{{person}}} 循环 {{#persons}} ...... {{/persons}} 数组循环的时候可以用 . 作为下标 { "musketeers": ["Athos", "Aramis", "Porthos", "D'Artagnan"] } {{#musketeers}} {{.}} {{/musketeers}} 对象 正常使用: { "name": { "first": "Michael", "last": "Jackson" }, "age": "RIP" } {{name.first}} {{name.last}} {{age}} 循环使用: { "stooges": [ { "name": "Moe" }, { "name": "Larry" }, { "name": "Curly" } ] } {{#stooges}} {{name}} {{/stooges}} if else {{#person}} ...... {{/person}} {{^person}} ...... {{

Mustache templates: How to output a block only once for non-empty lists

白昼怎懂夜的黑 提交于 2019-12-18 05:43:26
问题 If my list is empty, I want to output this: <div id="some-id"> </div> If my list is non-empty, I want to output this: <div id="some-id"> <ul> <li>Item 1</li> <li>Item 2</li> <li>etc</li> </ul> </div> Note that I output the <ul> and </ul> tags at most once , and only if the list is non-empty. The following code is close to how I would do this in PHP, but is obviously wrong: <div id="some-id"> {{#items}} <ul> {{/items}} {{#items}} <li>{{name}}</li> {{/items}} {{#items}} </ul> {{/items}} </div>