handlebars.js

how to pass parameters to Handlebars helper? What's the difference between options.hash & options.data

我的未来我决定 提交于 2019-12-03 10:45:34
Here's a typical Handlebars helper: Ember.Handlebars.helper 'myHelper', (value, options) -> ... According to this protip you can pass hash to Handlebars helpers. I looked over the source and found out that it provides both options.hash and options.data . I'm a bit confused as this wouldn't work as expected: {{#with controllers.currentCardCategory}} {{#each property in cardProperties}} <td class="td">{{cardProperty this property=property.symbol}}</td> {{/each}} {{/with}} this is the current Card record. Here I got property.symbol as string But this worked: {{#with controllers

Access values using {{#each}} in a one dimensional array

纵然是瞬间 提交于 2019-12-03 10:32:01
I've found a lot of examples of using the {{#each}} helper to iterate over multi-dimensional arrays, but I can't figure out how to access each value in a one-dimensional array. For example, take this array: skills: ['Design', 'Development', 'HTML5', 'CSS', 'JavaScript'], How do I output each item, in a helper like below? template: Handlebars.compile( '<div>' + '{{#each skills}} {{ the_item_output }} {{/each}}' + '</div>' ), What do I need to put in placed of {{ the_item_output }} to see the actual item? {{#each skills}} <li>{{this}}</li> {{/each}} An array of scalar values should make use of

Ember.js - doing it right (structure, includes, general questions)

巧了我就是萌 提交于 2019-12-03 10:09:14
问题 I'm playing around with ember.js and am stuck somehow finding out how to build up the structure the right way. I could follow all examples, but have some problems putting them all together. I'm using require.js and handlebars. My directory structure looks like this: - app - - controllers - - css - - helpers - - lib - - models - - routes - - templates - - - partials - - views My application.js looks like this: require.config({ paths:{ jquery:'lib/jquery-1.7.2', handlebars:'lib/handlebars',

Rendering a string array with handlebars

蓝咒 提交于 2019-12-03 09:19:28
Lets say I have an array like this in ember controller, selectedUsers: ["Popeye", "Sulley", "Gru"]; Now, how can i render each users in an unordered list using handlebars? Can i use the {{#Each}} helper? Stoic Yes, you should use an each loop: <ul> {{#each selectedUsers}} <li>{{ this }}</li> {{/each}} </ul> From the docs : You can iterate over a list using the built-in each helper. Inside the block, you can use this to reference the element being iterated over. <ul class="people_list"> {{#each people}} <li>{{this}}</li> {{/each}} </ul> when used with this context: { people: [ "Yehuda Katz",

SetTimeout vs. Ember.run.later in an ember app?

依然范特西╮ 提交于 2019-12-03 09:12:22
问题 Inside my handlebars template: Today's date: {{currentDate}} Current Time: {{currentTime}} Inside my helpers: Ember.Handlebars.registerBoundHelper 'currentDate', (option) -> moment().format('LL'); Ember.Handlebars.registerBoundHelper 'currentTime', (option) -> moment().format('h:mm:ss a'); How would I go about updating the currentTime to the view every 1 second? I have read the Ember recommends Ember.run.later but I can't quite figure out where to put it and how to call it using this helper.

How to use templating (handlebars, or any alternative) with Node.js and without using a framework (ex = express)?

半腔热情 提交于 2019-12-03 09:03:07
问题 For example, I have this JSON document "foo.json": { "foo": [ { "bar": "Hello World!" }, { "bar": "The End" } ] } In Node.js, I would like to use templating (handlebars or any) to generate a string from the JSON document, such as: <p>Hello World!</p><p>The End</p> ... And then assign that string value to a variable in Node.js. Finally, I'll concatenate more values to the variable and output the final variable value as an html document. Can this be done without using a framework like Express?

TypeError: Handlebars.registerHelper is not a function

本秂侑毒 提交于 2019-12-03 08:51:54
问题 I am brand new to node and handlebars as of two days ago so bear with me. I am trying to use custom handlebars helpers but am not entirely sure where to put it. I keep getting "TypeError: Handlebars.registerHelper is not a function" Right now I have it in my server.js file. Not sure if this is correct. var express = require('express'); var app = express(); var Handlebars = require('express-handlebars'); app.engine('handlebars', Handlebars({ defaultLayout: 'main' })); app.set('view engine',

Ember Interpolation in a href tag in handlebars template

倖福魔咒の 提交于 2019-12-03 08:04:34
I am trying to make a simple link to google maps with a dynamic address inserted into the href field. I have tried the code below plus tons of other messing around with no luck. How do you interpolate a dynamic ember string in a handlebars href field? I am using ember,rails, and handlebars. I know how to use bindAttr if I had the entire url stored with my model but I only have the address. Putting the google url with every model seemed unnecessary if i could just call it once in the view. <h1>{{name}}</h1> <div> <p><a {{bindAttr href='http://maps.com/?1=address'}}>{{address}}</a></p> </div>

Get DOM element using meteor template helpers

妖精的绣舞 提交于 2019-12-03 07:44:15
问题 For example my html is <template name="atest"> <a href="{{route}}" data-test="test">Click</a> </template> In meteor template helpers, I want to be able to select the anchor tag. Template.atest.route = function() { console.log(this.data-test); }; I am not sure if this can be done or not, but certainly, it cannot be done via any method I have tried. I know there is a way to pass argument in a template instance, but I don't want that. I want to be able to select that anchor tag that template

Using Handlebars templates with external JSON

≯℡__Kan透↙ 提交于 2019-12-03 06:25:48
问题 I feel really stupid, but I can't figure this out. I'm trying out Handlebars.js, but I can't get it to display data from the Twitter API. Here's what I've got: $.ajax({ url : 'http://twitter.com/statuses/user_timeline/alexlande.json', dataType : 'jsonp', success : function( tweets ) { var source = $('#tweet-template').html(); var template = Handlebars.compile(source); var context = tweets; $('#container').html(template(context)); } }); That doesn't display anything in my template, but the