handlebars.js

Accessing the current model within a yield

假如想象 提交于 2020-01-17 04:41:13
问题 I'm looking for how to access the current model with-in an each from a yield statement. Any ideas? Model models: [{ id: 1, name:'Red', value: '#ff0000' }, { id: 2, name:'Yellow', value: '#ffff00' }, { id: 3, name:'Blue', value: '#0000ff' }]; Template {{#table-list models=models config=colorModelTableListConfig}} {{model.id}} {{model.name}} {{model.value}} {{/table-list}} Component (table-list) <!-- Searching markup--> <table> {{#each th in config.tableHeaders}} <th>{{th}}</th> {{/each}} {{

Ember Handlebars not automatically putting model in scope

ⅰ亾dé卋堺 提交于 2020-01-15 07:04:25
问题 Typically, Ember automatically puts the route's model in scope when rendering a handlebars template: <h1>{{ title }}</h1> Renders: <h1>My Title</h1> For some reason, it's not doing that for me with a particular route. I'm just getting an empty <h1></h1> . However, if I manually put it into scope: <h1>{{ model.title }}</h1> Then it works as expected. What might be causing this behavior? My route is basic: MeetingsShowRoute = Ember.Route.extend model: (params) -> @store.find('meeting', params

Ember Handlebars not automatically putting model in scope

送分小仙女□ 提交于 2020-01-15 07:04:16
问题 Typically, Ember automatically puts the route's model in scope when rendering a handlebars template: <h1>{{ title }}</h1> Renders: <h1>My Title</h1> For some reason, it's not doing that for me with a particular route. I'm just getting an empty <h1></h1> . However, if I manually put it into scope: <h1>{{ model.title }}</h1> Then it works as expected. What might be causing this behavior? My route is basic: MeetingsShowRoute = Ember.Route.extend model: (params) -> @store.find('meeting', params

express3-handlebars and 18next-node - internationalisation based on page?

送分小仙女□ 提交于 2020-01-15 05:00:12
问题 my first question here - please go easy. I'm using express, express3-handlebars and i18next-node with node.js The plan is to work with a different translation namespace depending on which view (i.e. which handlebars file) is currently being served. So if we're looking at the page called ie(.hbs), i18next will look in the namespace called ie(.json) for the relevant language. This makes organisation and coordination of translations easier. This is how I'm currently doing it: first I send the

Minify HTML files in text/html templates

做~自己de王妃 提交于 2020-01-14 10:32:35
问题 I use mustache/handlebar templates. eg: <script id="contact-detail-template" type="text/html"> <div>... content to be compressed </div> </script> I am looking to compress/minify my HTML files in the templates for the best compression. YUIcompressor, closure does not work as they think that it is script and gives me script errors. HTMLCompressor does not touch them even as it thinks that it is a script. How do I minify the content in the script tags with type text/html? Can I use a library? If

How to get access to request object from custom handlebars helper

不想你离开。 提交于 2020-01-14 09:35:08
问题 I'm using handlebars with node.js and express and I have a custom registered helper for temperature display that I'd like to have access to a query parameter from the page URL. The concept behind the helper is to handle Fahrenheit to Celsius conversion automatically based on whether ?tempFormat=F or tempFormat=C is in the URL or not. Here's the pseudo code for the custom helper I'd like to have: hbs.registerHelper("formatTemp", function(temp) { if (query parameter says to use Fahrenheit) {

Handlebars and async call

帅比萌擦擦* 提交于 2020-01-13 18:58:08
问题 I use this helper to check wether an image exists or not: Handlebars.registerHelper('checkLogo', function(url) { UrlExists(url, function(status){ if(status === 200){ return new Handlebars.SafeString(url) } else if(status === 404){ console.log('no logo found'); } }); }); function UrlExists(url, cb){ $.ajax({ url: url, dataType: 'text', type: 'GET', complete: function(xhr){ if(typeof cb === 'function') cb.apply(this, [xhr.status]); } }); } I call it (with a url as arg) in my template like this:

How to use precompiled templates in Handlebars with RequireJS?

南楼画角 提交于 2020-01-12 07:52:05
问题 I'd like to precompile my Handlebars templates, but I'm not sure how this works in development mode. Is it common practice have some background process like Guard running to constantly monitor changes to Handlebars template files? I'm using RequireJS to pull in templates; e.g.: define(['jquery', 'handlebars', 'text!templates/my_template'], function($, Handlebars, myTemplate) { // ... var data = {"some": "data", "some_more": "data"}; var templateFn = Handlebars.compile(myTemplate); $('#target'

How can I precompile HandlebarsJS templates from Visual Studio?

走远了吗. 提交于 2020-01-11 19:38:20
问题 Is it possible to precompile Handlebars Templates from a postbuild event of Visual Studio or in the App_Start of a MVC web app? Thanks so much in advance. Dale 回答1: Sure, you have many options: You can install node.js for windows and npm, and configure a post-build event to the compilation (example here from previous question) If you're using ember.js, here's an implementation that uses bundle transformation to achieve precompilation. Another for ember.js that supports components, here's the

How to set a variable for the main handlebars layout without passing it to every route?

允我心安 提交于 2020-01-11 15:47:13
问题 I'm using handlebars with nodejs and express. This is my main.handlebars file: <!doctype html> <html> <head> ... </head> <body> <div class ="container"> ... <footer> © {{copyrightYear}} Meadowlark Travel </footer> </div> </body> </html> So far I'm passing the copyright year to every route: var date = new Date(); var copyrightYear = date.getFullYear(); app.get( '/', function( req, res) { res.render( 'home', { copyrightYear: copyrightYear } ); } ); Is it possible to set the copyrightYear