handlebars.js

Global properties in Express & Handlebars

二次信任 提交于 2019-12-22 07:42:33
问题 I'm using Handlebars (using express3-handlebars) for templates and Passport for authentication in a NodeJS app. All is working great but I wondered if there is a way to pass the req.user object created by Passport to Handlebars globally. So my header partial might look something like this: <header> <h1>My Title</h1> {{#if user}} <p>Hello {{user.name}}</p> {{else}} <p>Please <a href='/login'>Log In</a></p> {{/if}} </header> As it stands I have to pass the user object explicitly with every page

Read object properties in handlebars template

北城以北 提交于 2019-12-22 05:53:21
问题 Is there a some way to read object properties using handlebars or ember helpers? {{#each object in objects}} <tr> {{#each key in keys}} {{!- doesn't work, because object[key] isn't valid syntax I guess --}} <td>{{object[key]}}</td> {{/each}} </tr> {{/each}} I know that I can read properties like so {{object.someProperty}} , however in my case the list of properties which needs to be read is passed to a component as an argument (in my example it is called keys ). Maybe this function already

How to use .html file extensions for handlebars in express?

自古美人都是妖i 提交于 2019-12-22 05:28:30
问题 So I was wondering how I could use .html extensions instead of .handlebars or .hbs extensions. I am doing this so I can develop using regular html so that my frontend developers can seamless edit files in their IDEs without any extra configuration. Plus it will help installing html templates much faster into our express applications. 回答1: So I was able to do this by changing three things in my app.js file I hope this helps everyone out as much as it helped me! var express = require('express')

TypeScript Defining a hash table of functions

被刻印的时光 ゝ 提交于 2019-12-22 04:25:28
问题 I'm trying to create a definition file for Handlebars, for use with pre-compiled handlebar scripts. Handlebars will put pre-compiled scripts into a string indexed hash table of functions, but I can't figure out or find how this would be defined. A hypothetical definition would be: declare module Handlebars { export var templates: { (model:any) => string; }[index: string]; } but that's not a valid definition. The definition should work for a call like this: var myHtml = Handlebars.templates[

How to use autofocus with ember.js templates?

廉价感情. 提交于 2019-12-22 04:10:10
问题 I have a simple ember.js text field and I'm trying to add autofocus {{view PersonApp.SearchField placeholder="search..." valueBinding="searchText"}} PersonApp.SearchField = Ember.TextField.extend({ }); Can I add this in the javascript or is at as simple as a attribute in the template itself? 回答1: Update: More recent versions of Ember now have support for this built in, so you no longer need to reopen TextField to add an attributeBinding. As of January 2014 (commit fdfe8495), you can simply

Inserting a Model Property into an Img Element URL in Ember

守給你的承諾、 提交于 2019-12-22 04:05:55
问题 I have a Model with an image_id property. I have a View for that Model that contains an image element. I need to insert the id into the image element's src property to complete the URL of the image so that I'm effectively doing this: <img src="news + newsItem.imageID + .jpg"></img> My first attempt used a Handlebars helper: <img src="news{{newsImageURL newsItem.imageID}}.jpg"></img> But this also inserted Metamprph script tags around it: <img url="<script id='metamorph-10-start' type='text/x

Ember deeply nested routes do not keep parent dynamic parameter

吃可爱长大的小学妹 提交于 2019-12-22 04:03:59
问题 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

Calling Javascript function from handlebar

回眸只為那壹抹淺笑 提交于 2019-12-22 01:23:58
问题 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. 回答1: 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

Node.js - res.render won't update view on browser

安稳与你 提交于 2019-12-22 00:43:11
问题 I'm using express and handlebars to build a web app. When I attempt to render a new template, however, the browser doesn't get updated at all. The console output contains the rendered html, but the page on screen stays the same. My code: router.post('/login', function(req, res) { User.findByUsername(req.body.username, function(err, user) { if(err === null) { req.session.username = req.body.username; req.currentUser = user; console.log("rendering"); //prints res.render('x.handlebars',

Ember Data sideloaded properties being dropped on a model

ⅰ亾dé卋堺 提交于 2019-12-21 22:10:06
问题 I'm working with Ember RC3 Ember Data Revision 12 Handlebars RC3 I have Ember Data sideloading relationships on many of my models, so that I can template the sideloaded relationships like so: // Models App.Client = DS.Model.extend({ company: DS.attr('string'), accountNumber: DS.attr('string'), startDate: DS.attr('mysqlDate'), // Relationships campaigns: DS.hasMany('App.Campaign'), users: DS.hasMany('App.User'), phones: DS.hasMany('App.Phone'), addresses: DS.hasMany('App.Address') }); App.User