handlebars.js

How to use multiple parameters in a handlebar helper with meteor?

喜夏-厌秋 提交于 2019-12-02 18:42:49
I am trying to create a custom helper using Meteor. Following to the doc here: https://github.com/meteor/meteor/wiki/Handlebars I have tried to define my helper as follows: Template.myTemplate.testHelper = function(foo, bar, options) { console.log(foo); console.log(bar); } My template looks like: <template name="myTemplate"> {{#testHelper "value1" "value2"}} {{/testHelper}} </template> Looking at my console output, I expected to see 2 lines of output: value1 value2 However my console looks like: value1 function (data) { // don't create spurious annotations when data is same // as before (or

How to find Array length inside the Handlebar templates?

风流意气都作罢 提交于 2019-12-02 18:40:25
I have a Handlebars template which is rendered using a json object. In this json I am sending an array. Like this: var json = { "array":["abc","def","ghi","jkl"] } Now in my template I want to find the length of this array. Something like: {{#each item}} {{ array.length }} {{/each}} Couldn't find it in the Handlebars documentation. Abhidev My Bad.... {{array.length}} actually worked inside the template. Should have checked/tested it before posting it here. In this case you need to reference the parent variable of the each from within the each block: {{#each array}} {{../array.length}} {{/each}

Easy way to precompile Emberjs Handlebar templates with nodejs?

人走茶凉 提交于 2019-12-02 18:31:20
I'm enjoying emberjs a lot and would like to take the next step in a couple of my small, mobile apps and precompile my Ember/Handlebars templates as part of my build process. I'd prefer to stay away from messing with Ruby and would like to use node.js as I'm more comfortable with using it. I believe what I want to use is Ember.Handlebars.precompile, but unfortunately I'm unable to load the canonical ember.js file in a node environment. Example of a naive attempt from the node repl: > var e = require('./ember'); ReferenceError: window is not defined at /Users/jeremyosborne/git/projects/ldls

How to decode HTML entity with Handlebars

不羁岁月 提交于 2019-12-02 18:13:51
I'm using the Handlebars templating engine on the app I'm building to render the data I get from the server. I know that it escapes HTML values by default and that you have to use the triple brackets {{{text}}} in order for text: <p>Example</p> to be rendered as an HTML element. The problem is, what do I do if the data I receive, including the HTML tags, is already escaped? So, if I receive data like: text: <p>Example</p> How do I force handlebars to translate it and render it as normal HTML? You have to decode it first, then pass it to handlebars with triple brackets. I know a small tip to

handlebars.js “each” loop inside another “each” loop 3

与世无争的帅哥 提交于 2019-12-02 18:08:29
Suppose I want to build a dynamic table. How do I run each inside each. If the only varible that represents current item is this . {{#each by_width}} {{#each by_height}} {{this}} // how do refer to this from the outer loop? {{/each}} {{/each}} You can use ../ to access the parent in a Handlebars template: {{#each by_width}} {{#each by_height}} w: {{../this}} h: {{this}} {{/each}} {{/each}} That of course assumes that by_height is inside each element of by_width , if they're both at the top level then you'd need another ../ : {{#each by_width}} {{#each ../by_height}} w: {{../this}} h: {{this}}

backbone.marionette + i18n + handlebars

荒凉一梦 提交于 2019-12-02 17:47:59
Can some one post an example of combining these libraries together? including the handler for the i18n and marionette. Thanks point backbone.marionette templates to compile hendlebars. this can be done on your main.js: Backbone.Marionette.TemplateCache.prototype.compileTemplate = function(rawTemplate) { return Handlebars.compile(rawTemplate); }; configure your app to use handlebars and i18n: this can be done on your config.js: require.config({ // Initialize the application with the main application file deps: ["main"], paths: { libs: "../assets/js/libs", plugins: "../assets/js/plugins", //

Use Handlebars.js with Backbone.Marionette

做~自己de王妃 提交于 2019-12-02 17:39:36
Is it possible to use the Handlebars.js with the Backbone.Marionette extension without reimplementing the Views render function? It seems that Marionette is relying on the convention that you use Backbone.js with underscores templating engine. But I really like the handlebar approach so I'm asking if I can the high-level-tools of Marionette with handlebars. brettjonesdev A simple way to use Handlebars with Marionette is simply to define template in each View as a pre-compiled Handlebars template function. For instance: var MyView = Backbone.Marionette.ItemView.extend({ template: Handlebars

app.set and app.engine in Express

怎甘沉沦 提交于 2019-12-02 17:38:57
I am following a Node.js tutorial . Two lines for which I am not sure are: app.set('view engine', 'html'); app.engine('html', hbs.__express); I checked the documentation for app.set and it only tells me: Assigns setting name to value. But my question is what's the relevance of using this. I googled it and wherever app.engine is used app.set is called before. Let me know the significance of using app.set before the app.engine . EDIT I found the following line, but I am still unclear as I am using template engine very first time: But we can tell Express to treat HTML files as dynamic by using

Is it possible to load handlebar template with script tag? Or define handlebar templates programmatically in Ember.js

ぐ巨炮叔叔 提交于 2019-12-02 17:12:54
Simply enough I do not want to define all my handlebar templates in my html file I tried this <script type="text/x-handlebars" data-template-name="nav-bar" src="template.handlebar"></script> But this did not work. Can I not define templates my template programmatically or even just load handlebar files so that I can reuse and also I feel it makes things a bit more maintainable. I tried just loading them with ajax and appending them to the head, this works fine I can see it there but ember.js doesn't read it after ember has already been loaded and the templates are not defined. Or define

Check for a value equals to in Ember Handlebar If block helper

二次信任 提交于 2019-12-02 16:58:25
How do we check for a value equality in ember.js 's If-block helper? {{#if person=="John"}} How do we perform above in handlebars? Jo Liss The {{#if}} helper can only test for properties, not arbitrary expressions. The best thing to do in cases like this is therefore to write a property computing whatever conditional you want to test for. personIsJohn: function() { return this.get('person') === 'John'; }.property('person') Then do {{#if personIsJohn}} . Note: If you find this too limiting, you can also register your own more powerful if helper . Use an Ember.Component , thus avoid repetitively