handlebars.js

Access attributes of the DOM elements from ember.js views

泪湿孤枕 提交于 2019-12-10 16:27:15
问题 How can I access attributes of DOM elements that are being inserted by ember.js view, from within the view itself. Here is a short example. Lets say I have the following cat.handlebars template: {{#collection contentBinding="App.catsController"}} <div class="cat" {{bindAttr id="view.content.id"}}></div> {{/collection}} which is used in this view: App.CatView = Ember.View.extend({ templateName: 'cat', catsBinding: 'App.catsController', didInsertElement: () -> #need to get the id of each DIV

Ember hide parent template when viewing sub-route

白昼怎懂夜的黑 提交于 2019-12-10 16:05:36
问题 I am making a simple blog for my website with Ember. My routes: Router.map(function() { this.route('home', { path: '/' }); this.route('blog', function() { this.route('post', {path: '/:post_id'}); }); }); I want it so when I click on a post in /blog and wind up at /blog/:post_id I hide the content of the blog.hbs file and only show the blog/post.hbs content. I tried specifying the render template explicitly in my post.js route file, but things kept working in the same fashion. export default

How to use one-way binding on emberjs?

痴心易碎 提交于 2019-12-10 13:59:29
问题 I'm starting to play around with ember but one thing I haven't been able to wrap my head around is how to use one-way bindings, consider the following code: HTML <script type="text/x-handlebars"> <h1>Some App</h1> <p> My Name is: {{name}} </p> <form {{action 'updateName' on="submit"}}> {{view Ember.TextField valueBinding="name"}} <input type="submit" value="Save"> </form> </script> JS var App = Ember.Application.create(); App.ApplicationRoute = Ember.Route.extend({ model: function() { return

Express res.locals.someVariable use in hbs (handlebars template)

帅比萌擦擦* 提交于 2019-12-10 13:18:53
问题 I am trying to pass my session variables to my handlebars templates but am getting stuck. Right now I am using this in my app.configure function: app.use(function(req, res, next){ res.locals.session = req.session; console.log(res.locals.session); next(); }); It logs correctly to the console, but when I try to use the "session" variable in my handlebars template, nothing shows up. Here is part of my template: <body> <nav> {{> topBarPartial}} {{> secondaryBarPartial}} </nav> <div> <p>before</p>

Interpret html string using handlebars but escape script tags

南笙酒味 提交于 2019-12-10 13:12:22
问题 I'm bringing in a string of html for my page and I consider it html-safe except for script tags. I'm aware that triple braces will escape the html, what are the steps to leave out any script tags? Example var foo = "<h1>Foo</h1><script>some script that might possibly be in here</script><p>bar</p> then in my .hbs: {{{foo}}} I would like to see the h1 and the paragraph but have scripts left out. Thanks in advance. 回答1: You have a couple of options: Remove the script tags before passing it as

Handlebars.js: Nested templates strip “safe” HTML

寵の児 提交于 2019-12-10 13:01:42
问题 I'm trying to render a highly variable set of data using a series of nested Handlebars templates and the result that is coming out is completely stripped of HTML tags, despite using a 'triple-stash' and returning a SafeString. I have data that looks similar to: { "type": "person", "details": [ {"name": "firstname", "value": "joe"}, {"name": "lastname", "value": "smith"}, { "name": "company", "value": "acme", "details": [ {"name": "address", "value": "123 Main St; Somewhere, CA"}, {"name":

Displaying user parameters in a meteor template

梦想与她 提交于 2019-12-10 12:54:27
问题 I'm trying to work out how to do something really simple but it has me stumped. I'm trying to simply display the user name and some of the profile parameters of the currently logged in user and I'm not getting far. The searching I've done so far seems to indicate that I need to use a helper function to access things like Meteor.user().profile.name setting it to a variable that I can then use in handlebars. Is this correct? Is it not possible to simply {{Meteor.user().profile.name}} in the

How to remove newlines generated by Handlebars?

旧城冷巷雨未停 提交于 2019-12-10 12:44:29
问题 Suppose I have a template like the following: start {{#if data}} data {{/if}} end Regardless of what I pass to the template, it will always have two extra newlines: start data end Is there a way to have Handlebars not generate the newlines that the tags were occupying (without moving the tags themselves)? eg. start data end The reason why I want this is because there are cases (like in XML), where newlines are not desirable. For example the following: <parent> {{#each}} <child>{{.}}</child> {

Handlebars: multiple conditions IF statement?

谁说胖子不能爱 提交于 2019-12-10 12:29:54
问题 I didn't find this was possible in Handlebars... I need something like this: {{#if A || B || C}} something {{/if}} Is that possible to achieve? I have looked at this answer, but as I need for 3 variables (A, B, C) I don't really know how to apply it. Any ideas? 回答1: They do not have multiple conditions. But you can achieve it by nesting. This works: {{#if A}} {{#if B}} {{#if C}} something {{/if}} {{/if}} {{/if}} 回答2: What about this? {{#if A}} something {{else if B}} someting B {{else if C}}

Handlebars condition based on lookup

瘦欲@ 提交于 2019-12-10 10:27:53
问题 I have the following data structure: { things: [ "desk", "chair", "pen", "book", "lamp" ], owners: [ "Julia", "Sandra", "John", "Paul" ] } What's working: This handleblars template: {{#each things}} <p>This {{this}} belongs to {{lookup ../owners @index}}</p> {{/each}} Correctly outputs: This desk belongs to Julia This chair belongs to Sandra This pen belongs to John This book belongs to Paul This lamp belongs to What's not working: Now, I'd like to add a condition because the last thing might