mustache

Mustache: Retrieve list/hash of tags from a template?

懵懂的女人 提交于 2019-12-07 19:23:38
问题 All the documentation and examples of Mustache I've seen show how to use a hash to populate a template. I'm interested in going the other direction. EG, if I have this: Hello {{name}} Can mustache generate this (pseudo-code): tags = 'name' I'm using the PHP flavor of Mustache, but I'm not too particular about the language. What I'm trying to do is build a system where people can create templates with Mustache tags, and another developer can quickly see what data the template will need. Is

Dynamic tables with Mustache using dynamic arrays

纵饮孤独 提交于 2019-12-07 15:42:43
问题 I am wondering if there is a more graceful solution to my current solution for the following problem Problem: Generate dynamic tables from a dynamic array with Mustache given that: Total column count is unknown Only one or two column names are known and must be rendered conditionally Helper functions may not be used Data is only provided in arrays. Not model classes Typical data-set with variable column count where ID is the only column know to always be provided: [id*] [Col-1] [Col-2] [Col-3

Mustache.js - How do you hook up events?

僤鯓⒐⒋嵵緔 提交于 2019-12-07 14:03:15
问题 I'm considering using Mustache.js for a small project I'm working on.... The one thing that I haven't seen an answer for is - Which is the best way to go about hooking up events? I was thing of creating a tree menu with mustache but I can't think which would be the best or cleanest way to hook up events to each node? 回答1: Mustache is a template engine; it's concerned only with markup, not behavior. To wire in events you should use the same best practices with HTML generated by hand or with

How to set the selected item in a radio button group in handlebars template?

你离开我真会死。 提交于 2019-12-07 06:13:01
问题 In a handlebars template, how do you set a radio button group to the right value using only the template? Can this be done directly in the template? For an example, let's say there's a radio button group like this: <label><input type="radio" name="mode" value="auto">Auto</label><br> <label><input type="radio" name="mode" value="on">On</label><br> <label><input type="radio" name="mode" value="off">Off</label><br> The data coming into the template has a value for mode: {mode: "on"} I want to

Why should we wrap our templates inside script blocks?

痞子三分冷 提交于 2019-12-07 01:26:16
问题 Background All the JS template engines recommend putting your template text inside script blocks like so: <script id="peopleTemplate" type="text/template"> {#people} <div class="person">Name: {firstName} {lastName}</div> {/people} </script> but many developers (understandably) dislike this because they lose HTML syntax highlighting in their code editor inside the script block. I've seen the workarounds like this: Keep correct HTML syntax highlighting in <script> "text/html" templates . This

PHP Mustache. Implicit iterator: How to get key of current value(numeric php array)

依然范特西╮ 提交于 2019-12-07 01:02:39
问题 If I have php array like this: $a = array ( 99 => 'Something1', 184 => 'Something2', ); And keys present important information - It can be some constant values, ids e.t.c Then how can I get key of current element from templete. For example: {{#data}} {.} - it is current value, but I need key also. {{/data}} In our system too much these kind of arrays and it is uncomfortably re-parse them before. What's better solution for this? Thank you very much! 回答1: It is not possible to iterate over an

javascript / jquery - creating an object in a particular format from a loop

巧了我就是萌 提交于 2019-12-06 21:18:28
I'm trying to get some data into this format, for use with a templating system called mustache: { "repo": [ { "name": "resque" }, { "name": "hub" }, { "name": "rip" }, ] } and what I currently have is this: for (childIndex in scenes[sceneID].children) { childSceneID = scenes[sceneID].children[childIndex]; childScene = scenes[childSceneID]; } So I somehow need to make each childScene the "name" in the "repo" object. Does anyone know how to do this? This is the mustache documentation: http://mustache.github.com/mustache.5.html Is this what you meant?: var repo = []; for (childIndex in scenes

Yii 2 —— 基于Mustache的页面多语言解决方案

心不动则不痛 提交于 2019-12-06 18:25:43
在Yii 2中,官方的页面多语言解决方案有两个: 方案1,使用Yii::t()函数,在页面中需要输出文字的地方,使用类似如下代码: <?= Yii::t(‘views/login’, ‘hello’)?> 这样做的后果是页面上大量充斥着类似的代码,导致页面可读性很差,而且对于同一个页面来说,Yii::t()函数的第一个参数基本上都是一样的,看到这些重复代码,也是心塞。我曾经在项目中采用这种方式实现多语言,一个简单的登录页面都能写到心烦的要命。 方案2,为指定语言做一个专门的视图,假设你有个页面是英文的,想再做个中文页面,可是中英文页面布局等相差很大,不是简单的翻译文字,那么在Yii 2中,可以在该页面的目录下,再建立一个zh-CN目录,然后在这个目录下建立一个同名的视图文件,页面内容用中文实现即可。这个我会专门再有文章说明如何实现。 如果中英文页面布局基本一样,只是文字有变化,那么建议还是不要用方案2了,宁可用方案1降低可读性,否则一旦页面内容有修改,两个页面之间的内容同步会搞到你怀疑人生。 总之,不管是方案1还是2,我都不喜欢,想要寻找一种简洁明了的页面多语言方案,页面看起来干净清爽,又不需要为每个语言做单独的页面。 那么怎样才能做到呢,我从Mustache中找到了实现的方案,假设下面是一个视图的代码: <h3>{{基本信息}}</h3> <table class="table

$.mustache() is defined, but Mustache isn't defined when mustache() is invoked

青春壹個敷衍的年華 提交于 2019-12-06 17:49:26
I am trying to use Mustache along with requireJS and jQuery, and it seems that it is being loaded into the browser since Chrome's console outputs correctly: >$.mustache <function (template, view, partials) { return Mustache.render(template, view, partials); } But when I try to use the mustache function it gives the error ReferenceError: Mustache is not defined and points to line 588 in the mustache.js file itself: $.mustache = function (template, view, partials) { return Mustache.render(template, view, partials); }; Here is how I'm invoking it in the main.js file: require(['mustache'],

Mustache: Retrieve list/hash of tags from a template?

我只是一个虾纸丫 提交于 2019-12-06 14:17:55
All the documentation and examples of Mustache I've seen show how to use a hash to populate a template. I'm interested in going the other direction. EG, if I have this: Hello {{name}} Can mustache generate this (pseudo-code): tags = 'name' I'm using the PHP flavor of Mustache, but I'm not too particular about the language. What I'm trying to do is build a system where people can create templates with Mustache tags, and another developer can quickly see what data the template will need. Is this something Mustache can do, or am I going to have to do some fun regex magic? You could use Hogan.js