handlebars.js

Promise value not put into template after resolved

孤人 提交于 2019-11-30 22:17:48
im fairly new to javascript and promises, so I might not get all the basic concepts,but im trying. I have a function in my model that checks the friendshiptstatus: friendShipStatus: function() { var self = this; return Ember.RSVP.all([this.container.lookup('user:current'), this.get('myFriends'), this.get('friendsWithMe'), this.get('friends')]).then(function(result){ var user = result[0], myFriends = result[1], friendsWithMe = result[2], friends = result[3] if(friends.contains(user)){ return 2; } else if(friendsWithMe.contains(user)){ return 4; } else if(myFriends.contains(user)){ return 1; }

Is there a ternary operator in handlebars.js?

风流意气都作罢 提交于 2019-11-30 21:50:13
问题 In Handlebars, is there a ternary operator? I don't mean if else ; I mean like a == true ? "a" : "b" . 回答1: You can build your own helper in handlbars if you really want to. Something like ternary(a==true, "a", "b") . For more information on that see the documentation. The idea from m90 is not the idea behind handlebars. The idea is to not have explicit code in your templates, only calls to helpers and objects. 回答2: The if helper can be used as a ternary operator by passing three arguments to

Handlebars registerHelper serverside with Expressjs

爱⌒轻易说出口 提交于 2019-11-30 21:23:40
I am using expressjs with handlebars as templating engine with following code in Webstorm IDE with express generator.There is no visible handlebars require in the code (I guess express generator has it someplace else which is not visible) var app = express(); . . app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'hbs'); How do i use registerHelper on serverside in this situation ? My other renderings and partials are working.So handlebars is doing its work.Its just that registerHelper seems to be cause of worry. I think express-generator just sets view engine to hbs only.

webpack Module not found: Error: Can't resolve 'jquery'

≯℡__Kan透↙ 提交于 2019-11-30 20:20:10
When I run the 'webpack' command, I get this error: ERROR in ./js/main.js Module not found: Error: Can't resolve 'jquery' in '...\js' @ ./js/main.js 3:0-16 4:0-23 In package.json I have: "devDependencies": { "handlebars": "^4.0.6", "handlebars-loader": "^1.4.0", "jquery": "^3.2.1", "path": "^0.12.7" }, in webpack.config.js: var path = require("path"); module.exports = { entry: "./js/main.js", output: { path: __dirname + "/js", filename: "scripts-bundled.js" }, resolve: { modules: [ path.join(__dirname, "js/helpers") ] }, module: { loaders: [ {test: /\.hbs$/, loader: "handlebars-loader"} ] } };

Handlebar helper inside {{#each}}

狂风中的少年 提交于 2019-11-30 19:36:34
I try to call a registered handlebar helper inside a {{#each}} loop. Unfortunately Ember.js complains because it tries to resolve the helper as a property of the controller rather than a helper. Handlebars.registerHelper('testHelper', function(name) { return 'foo: ' + name }); (names and content are just dummy values to show the example) {{#each entry in App.testController}} <div>{{{testHelper entry.name}}}</div> {{/each}} The error that the Ember.js prints is: Uncaught Error: Handlebars error: Could not find property 'testHelper' on object <App.testController:ember254>. How do I need to call

How to render a (Twitter Bootstrap) grid using Ember.js and Handlebars.js?

末鹿安然 提交于 2019-11-30 17:44:49
问题 I’m having a hard time figuring a way to render the following markup using Ember.Handlebars: <div class="row-fluid"> <div class="span4">Item #1 (row #1 / column #1)</div> <div class="span4">Item #2 (row #1 / column #2)</div> <div class="span4">Item #3 (row #1 / column #3)</div> </div> <div class="row-fluid"> <div class="span4">Item #4 (row #2 / column #1)</div> <div class="span4">Item #5 (row #2 / column #2)</div> <div class="span4">Item #6 (row #2 / column #3)</div> </div> <div class="row

How to see all available variables in handlebars template

夙愿已清 提交于 2019-11-30 16:41:31
问题 I'm working on my first Ember.js app and am having some trouble connecting all the dots. It would be really helpful if I could just see all the variables available within a given handlebars template. There is a related question, but you have to know the variable that is in scope to use it: How do I add console.log() JavaScript logic inside of a Handlebars template? How can I output all the variables? 回答1: a good option is to debug the value of 'this' in a template using the Handlebars helpers

Recursive view in handlebars template not working after upgrading to Ember 0.9.6

大兔子大兔子 提交于 2019-11-30 15:59:01
I used to be able to do something like this to get a nested unordered list of items: Javascript: App.Menu = Em.View.extend({ controller: App.menuController.create({}), tagName: 'ul', templateName: 'Menu', pageBinding: 'controller.page' }); Handlebars: <li> {{page.menuTitle}} {{#each page.childrenPages}} {{view App.Menu pageBinding="this"}} {{/each}} </li> index.html: <script type="text/x-handlebars"> {{view App.Menu}} </script> Now after updating to the latest Ember.js (0.9.6), only the last item of any given collection of items is being displayed (as a single <li> within the <ul> ). In

Handlebar.js to include another template in parent template

狂风中的少年 提交于 2019-11-30 14:13:56
I have an error page , which is a handlebar.js template. I need to load this template in the current page handlebar.js template. A typical include < file name > type, but could not found a way around in handlebar. Please advise me here . Thanks. Sounds like you're looking for a partial. A partial is a template fragment that you want to include in several other templates. You'd do something like this in your templates: <script id="error" type="text/x-handlebars"> <!-- Error display stuff goes here --> </script> <script id="t" type="text/x-handlebars"> {{> error}} </script> Then register the

node express how to render handlebars html page to file

旧巷老猫 提交于 2019-11-30 13:41:26
I want to convert some html page to pdf via wkhtmltopdf. However, the html page I want to convert to pdf is dynamically generated using handlebars. So I think one solution maybe to generate the html page via handlebars but to a file (html file). Then, convert that file to pdf using hkhtmltopdf, then allow the user to, somehow, download the pdf. So, my question is: how can I render the (handlebars) dynamically generated html page to a file? Thanks and bye ... Simple example for create file. var Handlebars = require('handlebars'); var source = "<p>Hello, my name is {{name}}. I am from {{hometown