handlebars.js

How to configure partials and layouts for Handlebars in Sails.js?

自作多情 提交于 2019-12-18 10:56:10
问题 I run Sails 0.9.7 and have installed Handlebars which is supported by Consolidate.js and therefore is supported by Sails I can serve pages from .handlebars files, it works just fine. I can't figure where, in Sails workflow, and in a Sails way , I should register partials, helpers etc... I'm more looking for best practices than just a working solution but any help will be appreciated. 回答1: I'm running v0.10 beta but this shouldn't affect how I got it working below: Engine should be handlebars

How to pass a parameter to pathFor in Handlebars for Iron-Router with Meteorite?

守給你的承諾、 提交于 2019-12-18 10:09:17
问题 I have a simple route with a parameter: this.route('article', { path: '/article/:_id', data: function() { return Articles.findOne(this.params._id); } }); I would like to have use the pathFor handlebars helper here with the _id: {{#each articles}} <li><a href="{{pathFor 'article' _id}}">{{title}}</a></li> {{/each}} This doesnt work for passing the _id tag into the url though... 回答1: <li><a href="{{pathFor 'article' _id=this._id }}">{{title}}</a></li> Thats how you pass a parameter 回答2: In your

Compile Ember template string and running it programmatically, without an Ember application?

↘锁芯ラ 提交于 2019-12-18 06:59:09
问题 I just want to run the template string against an object and examine the result I have a string that is a template. I've "compiled" it. Now I want to run it against an object and examine the result. But this doesn't work: var template = '<div>{{#each items}}<div>{{item}}</div>{{/each}}</div>'; var compiled = Ember.Handlebars.compile(template); var result = compiled({ items: [1, 2, 3] }); // ERRORS What I want to get is the DOM result of running my compiled string against an object. In other

Ember template not updating from arraycontroller

末鹿安然 提交于 2019-12-18 05:25:26
问题 In my app, a user can enter a description of a friend or upvote a description that is already present. Both methods (createDescription and upvoteDescription) persist in the database. upvoteDescription changes the DOM, but createDescription does not. It may be because I'm passing a parameter in the model, but I can't get around that -- the api needs it. //descriptions route App.DescriptionsRoute = Ember.Route.extend({ ... model: function () { var store = this.get('store'), friend = this

How to update req.user session object set by passportjs?

試著忘記壹切 提交于 2019-12-18 04:34:11
问题 I'm trying to do this since a lot of days but all my tests fails... Users on my platform connect them by using passportjs strategies (paypal, facebook, google...). When the user is connected I write his nickname on the right in the header. The html code of the header is generated from a handlebars template, and when this partial is served by expressjs, I send the req.user session object to the template in order to write nickname and other informations... By the way, this works great but I

How to outsource a template js to a different file when using Handlebars.js

半腔热情 提交于 2019-12-18 04:22:17
问题 I have this template script <script id="some-template" type="text/x-handlebars-template"> {{#users}} {username} {email} </script> I want to out-source it to a file called "user_template.js" which will look like this: {{#users}} {username} {email} and make in the main index.html this link: <script id="some-template" type="text/x-handlebars-template" src="user_template.js"></script> The problem is - it doesn't work - how do I do it? 回答1: You can use ajax to load the template file. With jQuery:

node express how to render handlebars html page to file

不羁的心 提交于 2019-12-18 04:10:49
问题 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 ... 回答1: Simple example for create

node.js and Handlebars: HTML compiled is escaped

浪尽此生 提交于 2019-12-18 02:50:33
问题 Im using handlebars in a node aplication, and I have trouble. This is the template index.html {{CONTENT}} This is the code var fs = require("fs"); var handlebars = require("handlebars"); var data = { CONTENT: "<b>Hello world!</b>" }; var templateFile = fs.readFileSync('./index.html', 'utf8'); var template = handlebars.compile( templateFile ); var html = template(data); The problem is that the tags <B> are escaped to <B> How can I avoid this? 回答1: From handlebarsjs.com : Handlebars HTML

node.js and Handlebars: HTML compiled is escaped

泪湿孤枕 提交于 2019-12-18 02:50:01
问题 Im using handlebars in a node aplication, and I have trouble. This is the template index.html {{CONTENT}} This is the code var fs = require("fs"); var handlebars = require("handlebars"); var data = { CONTENT: "<b>Hello world!</b>" }; var templateFile = fs.readFileSync('./index.html', 'utf8'); var template = handlebars.compile( templateFile ); var html = template(data); The problem is that the tags <B> are escaped to <B> How can I avoid this? 回答1: From handlebarsjs.com : Handlebars HTML

Set the selected item in a select list based on template value

可紊 提交于 2019-12-17 23:35:03
问题 How can you correctly pre-populate a select control with the current value from the template? I have a simple form to edit a record where the values for the selected record are pre-populated when the form is shown. A bit like this: <input type="text" id="project_name_edit" value="{{selected_name}}"> But where I am using a select control I need to be able to interogate the template value and conditionally set the selected='selected' property for the correct option. <select id="project_status