handlebars.js

Updating Ember Nested Model and Template

醉酒当歌 提交于 2019-12-05 05:06:26
问题 I have a template which is backed by a model. It is a tree list view which has the first level folders. I have an action handler which is used to update the sub-child any of the first level folder. From the action I need to update the model so that the sub-child is updated in the template. I can add another first level folder by directly updating the model using pushObject. How can I add/update the sub-child nodes of any parent level folders. In template: <script type="text/x-handlebars"> <h2

Why should we wrap our templates inside script blocks?

只愿长相守 提交于 2019-12-05 05:01:21
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 question is not asking about workarounds. I know one danger is that web browsers will attempt to fix

Mustache (or Handlebars) iterating over two lists

落花浮王杯 提交于 2019-12-05 04:52:21
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}} and {{#digits}} {{.}} {{/digits}} but no matter which way I nest them I seem to get repeats instead of

Adding attributes to input element in Handlebars (used with Ember.JS 1.0)

烈酒焚心 提交于 2019-12-05 03:23:09
Let's say I have something like: {{input value=someModel }} And then I want to add the simple required HTML 5 attribute to the input. How would I do that? Note that I tried the following variations without success: {{input value=someModel required }} <!-- doesn't parse --> {{input value=someModel required='required' }} <!-- doesn't render the attribute --> {{view Ember.TextField valueBinding=someModel required='required' }} <!-- doesn't render the attribute --> <input required {{bindAttr value=someModel}} /> <!-- doesn't update the model, as expected --> Update: This question was for Ember 1.0

Using precompiled handlebars templates with Marionette

牧云@^-^@ 提交于 2019-12-05 02:30:58
问题 I'm using Marionette with requirejs and I would also like to use precompiled handlebars templates. How does this work? Here my current setup: require_main.js: requirejs.config({ baseUrl: "/", paths: { 'text': 'vendor/javascripts/text', 'backbone': "vendor/javascripts/backbone", 'backbone.wreqr': "vendor/javascripts/backbone.wreqr", 'backbone.babysitter': "vendor/javascripts/backbone.babysitter", 'jquery': "vendor/javascripts/jquery", 'jquery-ui': 'vendor/javascripts/jquery-ui', 'json2':

Handlebars parse error while compiling template

白昼怎懂夜的黑 提交于 2019-12-05 02:11:29
i am getting below error while compiling handlebars template with windows CMD. my handlebars client and server both are @1.3.0 please help me to identify where i am going wrong dashboard.handlebars code-- <ul class="small-block-grid-2 medium-block-grid-2 large-block-grid-2" style="text-align:center;"> <li> <div class="chart" data-percent="{{#getPercent reward_point.point_achived reward_point.point_available}}"> <span>{{#getPercent reward_point.point_achived reward_point.point_available}}%</span> <span style="font-size:.5em;display:inline-block;">{{reward_point.point_achived}}</span> <span

Ember deeply nested routes do not keep parent dynamic parameter

泄露秘密 提交于 2019-12-05 01:32:34
I've got this ember application: Ember : 1.3.2 Ember Model : 0.0.11 Handlebars : 1.3.0 jQuery : 1.9.1 Using this resource map: App.Router.map(function () { this.resource('dimensions', function() { this.resource('dimension', { path: ':dimension_id'}, function () { this.resource('value', { path: 'values/:value_id' }); }); }); }); And this allows me to embed {{outlet}} in "dimensions" template that fills with "dimension" template, and embed {{outlet}} in "dimension" template that fills with "value" template as well. All works very well except for the link-to helper in the "value" template, that

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

喜夏-厌秋 提交于 2019-12-05 00:20:19
{#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 , " Solution is not as nice as I'd hoped, but this works: {#each controller.content.assetAllocation.class}} {{_view.contentIndex}} {{/each}} Here's my way: {#each controller.content.assetAllocation.class as |item index|}} {{index}} - {{item}} {{/each}} The index is Zero-based numbering. So if you want to change it, just add an helper like this: Ember.Handlebars

Calling Javascript function from handlebar

安稳与你 提交于 2019-12-04 22:23:51
How can I call a JavaScript function from inside a handlebars script? Reason: I wasn't able to break the {{#each}} from inside handlebars. So I need to pass it to JavaScript to do the logic. Hüseyin BABAL You can do that with helpers; Handlebars.registerHelper("printItems", function(items) { var html = "<ul>"; items.forEach(function(entry) { html += "<li>" + entry + "</li>"; }); html += "</ul>"; return html; }); and in your handlebars template; {{printItems items}} Above code will put your items in list. For more details refer here . Go to helpers section Handlebars is a minimal tempting

How can I make HTML fill itself with the content from the JSON file using handlebars?

谁说胖子不能爱 提交于 2019-12-04 20:44:38
I need to make HTML fill itself with content from JSON file using the mustache, or handlebars. I created two simple HTML templates for testing (using handlebars ) and filled them with content from an external Javascript file . http://codepen.io/MaxVelichkin/pen/qNgxpB Now I need content to lay initially in a JSON file . I ran into two problems, but they both lie at the heart of solutions of the same main problem - creating a link between the content in the JSON file and HTML , so I decided to ask them in the same question. (If you think that it is necessary to ask these questions separately,