handlebars.js

Define array inside template for handlebars/ember?

浪子不回头ぞ 提交于 2019-12-10 10:15:14
问题 I have a handlebars template in an ember application. It accepts an array. I currently declare the array like this template: {{Gd-radio-input content=radioContent value="blue"}} Javascript: App.IndexController = Em.Controller.extend({ radioContent: [ {label: 'Red', value: 'red'}, {label: 'Blue', value: 'blue'}, {label: 'Green', value: 'green'}, {label: 'Yellow', value: 'yellow'}, ] }); For my purposes, I would like to define the array inside the template sometimes. I tried this, but javascrip

How to compile new templates at runtime in meteor?

痞子三分冷 提交于 2019-12-10 10:08:31
问题 How to compile new templates at runtime in meteor using Handlebars.js? var source = '<input type="text" value"{{title}}" />' ; var template = ***???***.compile(my_new_template, source); var context = {title: "My New Post", body: "This is my first post!"} Template.my_new_template.events({ 'click': function (e,sender) { var that=this; } }); var html = Template.my_new_template(context); $('#workspace').append(html); 回答1: Currently there is no way to compile the Handlebars string directly. Meteor

Mustache (or Handlebars) iterating over two lists

喜欢而已 提交于 2019-12-10 03:57:47
问题 I have two arrays: var content = { "girls": ["Maria", "Angela", "Bianca"], "digits": ["21.143.191.2", "123.456.78.90", "971.6.17.18.1"] }; and a template: <script id="template" type="text/template"> <ul> <li><a href="{{digits}}">{{girls}}</a></li> </ul> </script> I'd like the end result to be: <ul> <li><a href="21.143.191.2">Maria</a></li> <li><a href="123.456.78.90">Angela</a></li> <li><a href="971.6.17.18.1">Bianca</a></li> </ul> I've tried block mustaches like {{#girls}} {{.}} {{/girls}}

What is the correct way of getting the index of an array when iterating over it using Ember Handlebars?

拟墨画扇 提交于 2019-12-10 02:09:33
问题 {#each controller.content.assetAllocation.class}} {{@index}} {{/each}} I'm trying to run the code above, which is supposed to output the index of the array, but it produces an error saying: "Uncaught SyntaxError: Unexpected token , " 回答1: Solution is not as nice as I'd hoped, but this works: {#each controller.content.assetAllocation.class}} {{_view.contentIndex}} {{/each}} 回答2: Here's my way: {#each controller.content.assetAllocation.class as |item index|}} {{index}} - {{item}} {{/each}} The

how to show json object key and value using handlebar template?

霸气de小男生 提交于 2019-12-10 00:57:06
问题 I have started to learn handlebar.js . I am struggling to display json data . My json look like this: var data={ "record1": [ { "first": [ { "name":"john", "city":"newyork" }, { "name":"britto", "city":"bangalore" } ] }, {"second": [ { "name":"franklin", "city":"newyork" }, { "name":"leo", "city":"bangalore" } ] } ] }; here this json is coming from server response so I don't know any key and value. I have to show key and value dynamically by using handlebar ...I have tried with eachKey but I

Ember.js: replacing simple linkTo helper with a view

大憨熊 提交于 2019-12-09 22:47:59
问题 I've got an app with basic functionality built out. I'm not going through and adding additional features. In this case I need to convert a simple button, currently using linkTo , to a View. Problem is that I'm not sure how to convert one to the other and still keep the link intact. How do I do this conversion? Here's the code I have now: <script type="text/x-handlebars" data-template-name="accountItem"> {{#each account in controller}} {{#linkTo "account" account}} <img {{bindAttr src="account

How to implement nested each loops with custom helpers (handlebar)

北战南征 提交于 2019-12-09 18:32:13
问题 I am trying to build a table together with Ember.js and Handlebar.js. Unfortunately I got stuck at the way how to build the cells which consist of Ember.TextArea with valueBinding. The idea is the following. There is domain model project which has many entries (1 to n relation). Both domain models are different object and are not embedded (the entries are not embedded in the project). Every project has an array called keys which contains several strings (e.g. 'a', 'b', 'c', ...). Furthermore

Template was precompiled with an older version of Handlebars than the current runtime

左心房为你撑大大i 提交于 2019-12-09 17:58:50
问题 I have this error, but the different between this question and my question is that I'm using gulp instead grunt. First, my handlebar runtime is handlebars v4.0.5 (js file). The output of handlebar -v is 4.0.5 This is my gulpfile.js : var gulp = require('gulp'); var uglify = require('gulp-uglify'); var handlebars = require('gulp-handlebars'); var wrap = require('gulp-wrap'); var declare = require('gulp-declare'); var concat = require('gulp-concat'); gulp.task('default', ['templates','scripts']

Handlebars.js disable escaping with noEscape option?

那年仲夏 提交于 2019-12-09 14:52:17
问题 I have all my content pre-escaped, so rather than using the triple stash everywhere i would like to globally disable handlebars escaping. A quick search showed a similar feature which I can see in my build of handlebars, however I don't know how to turn it on. The pull request is here: https://github.com/wycats/handlebars.js/pull/121 I've tried adding Handlebars.Compiler.options.noEscape = true in my code but it always comes back with options undefined. Even after defining the options its not

Using grunt handlebars together with ember, to split templates in separate files

我是研究僧i 提交于 2019-12-09 12:31:34
问题 I am trying to split my ember.js handlebars templates in several files, in order to make the code base more manageable. Since we are using yeoman/grunt, I have come across this handlebars plugin. I have configured it as follows: handlebars: { compile: { options: { namespace: 'JST' }, files: { '<%= yeoman.dist %>/scripts/templates.js': [ '<%= yeoman.app %>/templates/*.hbs' ], } } } As suggested in the "Usage examples" section of the plugin. This is working as expected, generating a dist