handlebars.js

Handlebars specific - escape both single and double quotes when passing Handlebars expression

扶醉桌前 提交于 2019-12-03 15:44:28
问题 HTML and Handlebars: onclick='shareItem("{{name}}")'> Does not successfully pass a safely escaped name when it has double quotes in it. onclick="shareItem('{{name}}')"> Does not successfully pass a safely escaped name when it has single quotes in it. I need to handle both eventualities- and even in the same string. It feels sloppy to have to define a JS variable and pass it to a backslash adder. Is there a cleaner way to do this with Handlebars or Moustache? 回答1: You need to register a inline

Can Meteor child templates access parent template helpers?

懵懂的女人 提交于 2019-12-03 15:41:26
问题 Say we have a parent template and a child template: <template name="parent"> {{> child }} </template> <template name="child"> {{#if show}} //Do something {{/if}} </template> If we assign 'show' to the parent template: if (Meteor.isClient){ Template.parent.show = function(){ return Session.get('isShowing'); } } Is there any way for the child template to have access to it? 回答1: Edit You could make a universal handlebars helper so you could use Sessions values anywhere in your html: Client js

How to pass parameters with the action Helper of Ember.js?

喜你入骨 提交于 2019-12-03 15:14:09
问题 I have a list of items: <ul> {{#each applications}} <li> <a {{bindAttr href="url"}} {{action "appClicked" on="click"}}> {{name}} </a> </li> {{/each}} </ul> On click it calls the method appClicked of the view, that this template belongs to. I want to pass some information (for example, the name of the application) to the method appClicked . Something like, {{action "appClicked(name)" on="click"}} . Is it possible, and how? 回答1: I was thinking something more along the lines of this since you'll

Passing an array of objects to a partial - handlebars.js

旧城冷巷雨未停 提交于 2019-12-03 14:49:24
Im trying to pass an array of objects into a partial as an argument: {{> partial [{title: "hello", year: "2015"}, {title: "hello2" year: "2015"}] }} and then on the partial: <div> {{#each this}} <label>{{title}}</label> <label>{{year}}</label> {{/each}} </div> ... but nothing shows up. Is there a way to pass array data to a partial? Thanks in advance. Create a helper that parses the JSON and wrap your partial with this context. Template: {{#getJsonContext '[{"title": "hello", "year": "2015"}, {"title": "hello2" "year": "2015"}]'}} {{> partial this }} {{/getJsonContext}} Note that the names are

How do I create a component that generates Radio-buttons in Ember.js?

孤者浪人 提交于 2019-12-03 14:41:45
Can I and should i pass arrays to components in ember? For example if I wanted to template something that renders a couple of radiobuttons with labels: <label for="media">Media</label><input type="radio" name="entry.1602323871" value="media" id="media" /> <label for="guest">Guest</label><input type="radio" name="entry.1602323871" value="guest" id="guest" /> Could I somehow pass an array with this content and loop through it. Media, media Guest, guest Yeah, You can pass anything to components. Just a try to the radio-buttons //Basic radio Component App.RadioButton = Ember.Component.extend({

How to print key and values in Meteor Template?

≯℡__Kan透↙ 提交于 2019-12-03 13:48:15
I have JSON from helper { "Name": "abc", "Age": 24, "Address" { "street" : "xyz street", "city" : "zyz city", "country" : "XY" } } I want to print the address with key and values <template name="User"> {{#with user}} Name : {{Name}} Age : {{Age}} {{#each Address}} {{key}} : {{value}} //Here is my question {{/each}} {{/with}} </template> How to print key and values in a template? The {{#each}} block helper only accepts cursors and arrays arguments. You could override the Address helper to make it return an array instead of an object. Template.User.helpers({ Address: function(){ return _.map

Print the loop index in Meteor.js templates [duplicate]

梦想与她 提交于 2019-12-03 13:36:56
This question already has answers here : How can I get the index of an array in a Meteor template each loop? (6 answers) I have a list of objects in meteorjs which I am iterating in meteorjs templates like {{#each objects}} {{/each}} In the template I want to print the number of the loop iteration. That is, if the length of the objects list is 100 I want to print the numbers from 1 to 100 in the template. How can I do this? You can't do this at the moment without giving in an index in your helper, i.e Template.yourtemplatename.object_with_index = function() { var objects = Template

How to make a handlebars helper global (in expressjs)

馋奶兔 提交于 2019-12-03 13:23:42
问题 I've got a pretty simple handlebars helper file in helpers/handlebars.js : var hbs = require('express-handlebars'); hbs.registerHelper("inc", function(value, options) { return parseInt(value) + 1; }); However, as expected, I can't refer to the {{#inc}} helper because I didn't pass it into the res.render() function. Is there a way to make all helpers in my file global and "auto-included"? edit: After trying @1cgonza's awesome answer, I get: hbs.registerHelper("inc", function(value, options) {

Ember.js - “Cannot perform operations on a Metamorph that is not in the DOM” caused by template

橙三吉。 提交于 2019-12-03 12:46:35
I've been having an issue with Ember.js throwing the error: Uncaught Error: Cannot perform operations on a Metamorph that is not in the DOM. I found these two SO questions, both of which involve direct manipulation of the DOM, which is not the case in my app. Searching for the error message also returns numerous Github issues related to the same type of direct DOM manipulation. I was at a loss until I happened upon this issue on Github from a search entirely unrelated with the error message. Basically, the error boils down to a Handlebars expression enclosed within an HTML comment. It's

Re-Rendering Handlebars partial from backbone view

不想你离开。 提交于 2019-12-03 12:33:46
I have a view, which holds handlebars template. that template consist of another partial template. that partial template holds a list of results, which i am using in different parts of my app. anyhow, when trying to filter the results, i'd like to render only that part. meaning the backbone view should not render the whole view just the partial. can it be done? Yes, it's possible. The easiest way is to execute the whole template as you do when rendering the complete view, but only replace the the part you need in the view's el . Something like: template: Handlebars.compile(templateHtml),