mustache

How to define mustache partials in HTML?

限于喜欢 提交于 2019-12-02 15:52:38
this is my html: <script type="text/html" id="ul-template"> <ul id="list"> {{> li-templ}} </ul> </script> <script type="text/html" id="ul-template2"> <div id="list2"> {{> li-templ}} </div> </script> <script type="text/html" id="li-templ"> <p>{{ name }}</p> </script> as you can see, I want to reuse the #li-templ part, but it seems that I have to write it into a file called li-templ.mustache then I can include it as partial ? can I just define them in the single html file? I'm assuming you're using the JS flavor of Mustache. In mustache.js an object of partials may be passed as the third

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

主宰稳场 提交于 2019-12-02 14:10:01
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? 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 on the fly: Handler Handlebars.registerHelper('I18n', function(str){ return (I18n != undefined ? I18n.t(str)

AMD Module Loading Error with Mustache using RequireJS

▼魔方 西西 提交于 2019-12-02 13:04:36
问题 I am following the tuturoial here: http://backbonetutorials.com/organizing-backbone-using-modules/ and all I would like to do is use Mustache instead of underscore.js for my templating engine in a Backbone View. Everything is working as expected until I try to do the replacement of Mustache. Firebug gives me this: Load timeout for modules: Mustache My Mustache wrapper (in libs/mustache/mustache-wrap.js ) is like so: define(['libs/mustache/mustache'], function(){ // Tell Require.js that this

Text replacement: PHP/regex

若如初见. 提交于 2019-12-02 10:22:14
问题 I am presented with an HTML document similar to this in view source mode (the below is simplified for brevity): <html> <head> <title>System version: {{variable:system_version}}</title> </head> <body> <p>You are using system version {{variable:system_version}}</p> {{block:welcome}} <form> <input value="System version: {{variable:system_version}}"> <textarea> You are using system version {{variable:system_version}}. </textarea> </form> </body> </html> I have written some functions that can

How to get 406 Error (not acceptable) in jquery

馋奶兔 提交于 2019-12-02 09:42:08
I am doing error handling in my.js, where i am having cross domain call to other server, also for dynamic HTML template i am using Mustache.js. $.getJSON(url, function(data, textStatus, xhr) { $.each(data, function(i, data) { introPage(data); }); }).fail(function(Error) { alert(Error.status); }); function introPage(data ) { $.getJSON('myphp.php?jsoncallback=?&template='+testTemplate, function(msg) { // my operations }).error(function(data) { }); } We have .fail() in getJSON to catch the errors in getJSON . I am able to catch 404 error (not found) but when it comes to 406 error (not acceptable

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

喜欢而已 提交于 2019-12-02 08:01:19
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 = require('path'); const expressValidator = require('express-validator'); const mustacheExpress = require(

Text replacement: PHP/regex

[亡魂溺海] 提交于 2019-12-02 07:05:47
I am presented with an HTML document similar to this in view source mode (the below is simplified for brevity): <html> <head> <title>System version: {{variable:system_version}}</title> </head> <body> <p>You are using system version {{variable:system_version}}</p> {{block:welcome}} <form> <input value="System version: {{variable:system_version}}"> <textarea> You are using system version {{variable:system_version}}. </textarea> </form> </body> </html> I have written some functions that can replace these {{...}} type strings, but they need to be replaced selectively. In the example above, I want

AMD Module Loading Error with Mustache using RequireJS

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 04:09:12
I am following the tuturoial here: http://backbonetutorials.com/organizing-backbone-using-modules/ and all I would like to do is use Mustache instead of underscore.js for my templating engine in a Backbone View. Everything is working as expected until I try to do the replacement of Mustache. Firebug gives me this: Load timeout for modules: Mustache My Mustache wrapper (in libs/mustache/mustache-wrap.js ) is like so: define(['libs/mustache/mustache'], function(){ // Tell Require.js that this module returns a reference to Mustache return Mustache; }); Here is the code for my Backbone View: //

vue基础

半腔热情 提交于 2019-12-02 03:38:24
Mustach n如何将data中的文本数据,插入到HTML中呢? p我们已经学习过了,可以通过Mustache语法(也就是双大括号)。 pMustache: 胡子/胡须. n我们可以像下面这样来使用,并且数据是响应式的   v-once n但是,在某些情况下,我们可能不希望界面随意的跟随改变 p这个时候,我们就可以使用一个Vue的指令 nv-once: p该指令后面不需要跟任何表达式(比如之前的v-for后面是由跟表达式的) p该指令表示元素和组件(组件后面才会学习)只渲染一次,不会随着数据的改变而改变。 n代码如下: v-html n某些情况下,我们从服务器请求到的数据本身就是一个HTML代码 p如果我们直接通过{{}}来输出,会将HTML代码也一起输出。 p但是我们可能希望的是按照HTML格式进行解析,并且显示对应的内容。 n如果我们希望解析出HTML展示 p可以使用v-html指令     Ø该指令后面往往会跟上一个string类型     Ø会将string的html解析出来并且进行渲染 v-text nv-text作用和Mustache比较相似:都是用于将数据显示在界面中 nv-text通常情况下,接受一个string类型 v-pre nv-pre用于跳过这个元素和它子元素的编译过程,用于显示原本的Mustache语法。 n比如下面的代码:

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

◇◆丶佛笑我妖孽 提交于 2019-12-02 00:10:40
问题 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. 回答1: 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,