handlebars.js

Creating a dynamic string with bindAttr

夙愿已清 提交于 2019-12-06 08:08:46
I'd like to create a dynamic classname on an object with a value I'm getting from my model. One of the keys is named provider which contains either "twitter" or "facebook". What I'd like to do is to prepend the string "icon-" to the provider so that the resulting class is icon-twitter or icon-facebook . This is the code that I've got now. <i {{bindAttr class=":avatar-icon account.provider"}}></i> Ember offers a way to include a static string within the attribute by prepending : to it. You can see that I'm also adding a class called avatar-icon in this example. I've already tried :icon-account

How to pass Model route name item to linkTo in template in ember.js

天涯浪子 提交于 2019-12-06 07:06:56
How do I pass a route name to a {{linkTo}} dynamically? For example, given this code: App.Router.map(function() { this.resource('anon', {path: '/main'}, function() { this.route('home', {path:'/home'}); this.route('about', { path: '/about' }); this.route('contact', { path: '/contact' }); }); }); App.NavController = Ember.ArrayController.extend({ selectedNav:'', setNav:function(value){ var nav = App.Nav.find(value); var items = nav.get('navItems'); this.set('content', items); } }); these templates: <script type="text/x-handlebars" data-template-name="nav"> <ul class="nav"> {{#each in controller}

Ember: Error with named outlets

折月煮酒 提交于 2019-12-06 05:05:16
I do not know why my templates are not being rendered in the named outlets. This is my first stab at learning ember and I am stuck on the named outlets. I would like to render the sidebarTemplate in the {{outlet "sidebar"}} and the contentTemplate in the {{outlet "content"}} but I keep getting the following error in the console: "Error while processing route: posts Cannot read property 'connectOutlet' of undefined TypeError: Cannot read property 'connectOutlet' of undefined" Here is a fiddle to my code: http://jsfiddle.net/va71wwr9/ Here is my HTML: <script type="text/x-handlebars"> <div class

set focus in an ember application

廉价感情. 提交于 2019-12-06 05:03:42
I want to be able to set the focus to a textarea as a result of a mouse click not in that task area. As a minimal example, let's say that I'm starting with a text and if you click on it, it gets replaced with a textfield. I can achieve this by a handlebars script: <script type="text/x-handlebars"> {{#if isActive}} {{view Ember.TextField}} {{else}} <p {{action foo}}> Click Here to Enter text </p> {{/if}} </script> with a controller of App.ApplicationController = Ember.Controller.extend({ isActive: false, foo: function(){ this.set("isActive", true); } }); This works to create the textfield on

Ember link-to Set Active Class Immediately

痴心易碎 提交于 2019-12-06 03:33:30
I have a nav bar that has special CSS that shows up when a link has the "active" class on it. It looks something like this: <ul> <li>{{link-to "routeName"}}<i class="icon-up"></i>{{/link-to}}</li> {{!-- more list items like the previous one... --}} </ul> However, when I click on the link with "routeName" , a rather expensive query is made that may be slow at times. I have a LoadingRoute set up with a loading view that consists of a simple spinner, but it seems like the link does not receive the "active" class until the route's promise is resolved. Is there a Handlebars-friendly way to tell

Update part of HTML page without reloading the page using expressJs nodeJs Handlebars

﹥>﹥吖頭↗ 提交于 2019-12-06 03:10:54
I have the following express app which just renders the ecommerce.hbs page.On that page i have one section suppose To Do List section and it shows four to five tasks with checkbox.when I change the checkbox the attached script run and send the id of changed checkbox to routing file where i have get the id and run loop to change value from true to false and false to true.I have console the value and it returns correct value after click on checkbox but i stuck to send data back to the ecommerce.hbs page for To Do List section.How can i send data back to ecommerce.hbs page without reloading the

Node handlebars adds extra text node before rendered view

耗尽温柔 提交于 2019-12-06 02:40:12
I have the following issue: When rendering a view in a layout with handlebars, the engine adds an extra text node before the rendered view body <nav></nav> {{{body}}} <footer></footer> results in <nav></nav> " [empty text node here] " <rendered view> <footer></footer> That empty text node has its own height and breaks my CSS margins and paddings. Note that if I put the view HTML directly in the layout without using handlebars templating, there is no text node and everything is fine. Any ideas why is this happening and how to solve it? I think I found the reason, please check your partial view

Handlebars passing object into helper

别等时光非礼了梦想. 提交于 2019-12-06 02:37:17
问题 Currently I have an Ember object that looks like this: name: 'Bob' xs: { 'actual':50 'target':55 } I have around 5-6 fields similar to xs . I need a helper method that can take that xs object and then return whether or not the target has been hit. I thought of doing this: Handlebars.registerHelper('hasHitTarget', function(attribute) { if (attribute.actual >= attribute.target) { return block(this); } }); {{#each user in App.userController}} {{#hasHitTarget user.xs}} Target Hit {{/hasHitTarget}

Define array inside template for handlebars/ember?

送分小仙女□ 提交于 2019-12-06 02:11:16
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 hates me: {{Gd-radio-input content="[ {label: 'Red', value: 'red'}, {label: 'Blue', value: 'blue'},

Iterating over javascript objects with handlebars

风流意气都作罢 提交于 2019-12-06 01:56:17
I am trying to register helpers with Handlebars to allow iterating over JSON objects. This gist looked like an appropriate solution. I converted that into the following CoffeeScript. Nothing seems to happen when I use either of the helpers (that holds true for both vanilla JavaScript and the CoffeeScript version). Any ideas? $ -> Handlebars.registerHelper "key_value", (obj, fn)-> buffer = "" key for key in obj if obj.hasOwnProperty(key) buffer += fn({key: key, value: obj[key]}) buffer Handlebars.registerHelper "each_with_key", (obj, fn)-> context buffer = "" key keyName = fn.hash.key for key