mustache

Access Nested Backbone Model Attributes from Mustache Template

一笑奈何 提交于 2019-11-30 03:51:58
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 in my Mustache template. Hi {{FirstName}}, you live in {{Address.City}}. Obviously does not work. When I

iterate through JSON array with mustache

落花浮王杯 提交于 2019-11-30 02:07:23
问题 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! 回答1: mustache is logicless, so writing your own iteration/loop in it

Is it possible to have nested templates in Go using the standard library? (Google App Engine)

ε祈祈猫儿з 提交于 2019-11-29 18:42:26
How do I get nested templates like Jinja has in the python runtime. TBC what I mean is how do I have a bunch of templates inherit from a base templates, just filing in blocks of the base templates, like Jinja/django-templates does. Is it possible using just html/template in the standard library. If that is not a possibility, what are my alternatives. Mustache seems to be an option but would I then be missing out on those nice subtle features of html/template like the context sensitive escaping etc.? What other alternatives are ther? (Environment: Google App Engin, Go runtime v1, Dev - Mac OSx

Mustache JS Template with JSON Collection

不羁岁月 提交于 2019-11-29 16:38:27
Hi this is my first attempt to use MustacheJS with a JSON webservice in .net Currently I am struggling I can't seem to find what I am doing wrong setting this basic example: My Webservice is returing the following string: [ { "ShortDescription":"BOX", "Description":"BOXING", "Id":1 }, { "ShortDescription":"EPL", "Description":"ENGLISH PREMIER LEAGUE", "Id":2 } ] I have validated its syntax with this website: http://json.parser.online.fr/ and here is the HTML code I am using: google.load("jquery", "1"); google.setOnLoadCallback(function () { $(document).ready( function () { $.ajax({ url: "..

icanhaz/mustache loop (iterate through elements) js error

你说的曾经没有我的故事 提交于 2019-11-29 12:59:48
I'm trying to get icanhaz/mustache loop working, as defined in this answer and I'm getting following error in browser console: Uncaught Error: Syntax error, unrecognized expression: <option value="1">First</option> <option value="2">Second</option> Don't know why. I've just managed to spot that this is the line that causes the problem: ich.myTemplate(listOfStuff); This is my entire code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/tr/html4/transitional.dtd"> <html> <head> <title>icanhaz.js demo</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"

Mustache Templating: nested templates

时光毁灭记忆、已成空白 提交于 2019-11-29 11:38:41
问题 How can I use a nested template within mustache? Is there a way to do the same? var tmpl="{{#data}} {{values}} Name: {{name}} //{{another_templ({{name.value}})}} {{/values}} {{/data}}" Hope you guys got the question. I have not added the escape character for js validity since code is split across different lines. 回答1: You could use a lambda to nest the template: function nested_template(template_string, translate) { return function() { return function(text, render) { return Mustache.to_html

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

爱⌒轻易说出口 提交于 2019-11-29 09:20:17
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> If items is a 3 item list, I'm going to get 3 <ul> 's - obviously not what I want. I realise I could

关于模板引擎一

♀尐吖头ヾ 提交于 2019-11-29 08:08:36
本文转载于: 猿2048 网站⇒ 关于模板引擎一 前端模板引擎需要有开发时的透明性 透明性即指我在搭建好开发环境后,随手写代码随手刷新浏览器就能看到最新的效果,而不需要额外地执行任何命令或有任何的等待过程。 所以一切依赖编译过程的模板引擎并不适合前端使用,编译只能是模板引擎的一个特性,而不能是使用的前提 更严格地说,使用FileWatch等手段进行文件变更检测并自动编译也不在我的考虑范围之内,因为这会造成额外的等待, 由此可以推出,前端的模板引擎应该是具备 可在纯前端环境中解析使用 的能力的。 前端模板引擎要有良好的运行时调试能力 由于用户行为的不确定性、执行环境的不确定性、各种第三方脚本的影响等,前端很难做到完全的错误处理和跟踪,这也导致前端必然存在需要直接在线上排查问题的情况 而当问题出现在模板引擎这一层时,就需要模板引擎提供良好的调试能力 一般来说,编译后生成的函数的调试能力是弱于原先手动编写的模板片断的,因为自动生成的函数基本不具备可读性和可断点跟踪性 因此在这一点上,一个供前端使用的模板引擎应该具备在特定情况下从“执行编译后函数获取HTML”换回“解析原模板再执行函数获取HTML”的模式,即应该支持在两种模式间切换 或者更好地,一个强大的前端模板引擎编译生成的函数,可以使用Source Map或其它自定义的手段直接映射回原模板片段,不过现在并没有什么模板引擎实现了这一功能

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

。_饼干妹妹 提交于 2019-11-29 05:43:32
问题 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'); 回答1: 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

Mustache - How to detect array is not empty?

て烟熏妆下的殇ゞ 提交于 2019-11-29 02:10:16
问题 I want to implement the following logic with Mustache: {{#if users.length > 0}} <ul> {{#users}} <li>{{.}}</li> {{/users}} </ul> {{/if}} // eg. data = { users: ['Tom', 'Jerry'] } Should I modify the users structure to meet the need? For example: {{#hasUsers}} <ul> {{#users}} <li>{{.}}</li> {{/users}} </ul> {{/hasUsers}} // eg. data = { hasUsers: true, users: ['Tom', 'Jerry'] } 回答1: Sorry, this may be too late. But I had similar requirement and found a better way to do this: {{#users.length}}