handlebars.js

Backbone.js - How to use a custom model property in a template?

断了今生、忘了曾经 提交于 2019-11-27 18:24:58
问题 This might be a really simple question but I'm having a heck of a time finding an answer. Using backbone, I have this line: Person = Backbone.Model.extend(); I then use that in a collection filled from a URL. For the sake of the example, say I have a first and last name, and I want to do something like: Person = Backbone.Model.extend({ FullName: this.get("firstName") + " " + this.get("lastName") }); I can call that inside backbone using, for example, People.first().FullName(). But if I pass

Express.js hbs module - register partials from .hbs file

扶醉桌前 提交于 2019-11-27 17:51:55
I'm using the handlebars.js hbs wrapper in express.js . I have templates working fine, but I'm needing to add in partials to be rendered with my views. I'd like to do something like this: hbs.registerPartial('headPartial', 'header'); // where "header" is an .hbs file in my views folder However, it's throwing a "header partial can not be found". I can make the registerPartial work if I pass a string of html to the second param, but I'd like to use separate view files for my partials. I haven't found any documentation on this, but hoping I may just be missing something easy. Does anyone know how

Passing a function into a Handlebars template

本小妞迷上赌 提交于 2019-11-27 16:45:19
问题 I'm using (or at least starting with) HandlebarsJS for the html templates but I might have hit a dead end. What I want is to pass a function to the template, e.g. <div id="divTemplate"> <span onclick="{{func}}">{{text}}</span> </div> and then I would expect to have something like var source = $('#divTemplate').html(); var template = Handlebars.compile(source); var data = { "text": "Click here", "func": function(){ alert("Clicked"); } }; $('body').append(template(data)); But the function is

How can I determine the MD5 digest of a given asset in the Rails asset pipeline?

佐手、 提交于 2019-11-27 16:10:46
问题 I'm writing a Javascript-rich application in a Ruby on Rails 3.1 project and using Handlebars for my JS templating framework. I'm trying to figure out a way to dynamically append the MD5 digest of an asset (generated during asset precompilation on production) to my tags inside of my Handlebars template. I'm hoping that there's a hash with the asset path as the key and the MD5 digest as the value, but I haven't been able to find one. An ideal solution would be passing the hash from Ruby into

Using express handlebars with vue js

依然范特西╮ 提交于 2019-11-27 15:04:44
问题 I am building an app using express handlebars for server-side templating. On the client side, I want to use vue.js. However, they both share the same double brace notation {{ variable }} . Right now, my vue.js variables are not showing because my handlebars template is overriding it. For example: home.html: <div id="app"> {{message}} //this will not show up </div> home.js: new Vue({ el: '#app', data: { message: 'Hello Vue.js!' } }); HOWEVER, if I define message in my server side controller:

TypeError applying precompiled Handlebars templates with a context

无人久伴 提交于 2019-11-27 14:32:54
问题 Pardon the noob question but I simply can't get precompiled Handlebars templates to do anything but barf out TypeError: 'undefined' is not a function (evaluating 'templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data)') each time I apply a context to a (precompiled) template. Given the following files and contents: hello.handlebars : <p>Hello, {{name}}</p> templates.js : the result of compiling hello.handlebars via handlebars hello.handlebars -f

How can I yield multiple pieces of content into an ember.js component template?

纵然是瞬间 提交于 2019-11-27 13:47:53
问题 The goal is to define a structure of HTML that has more than one block of content that is declared by the caller. For example, a header, body, and content. The resulting markup should be: <header>My header</header> <div class="body">My body</div> <footer>My footer</footer> The template instantiating the component would define each of the three sections, My header , My body , and My footer . With Ruby on Rails, you would use content_for :header to capture the header content from the caller,

Setting up rake-pipeline for use with handlebars alongside Google App Engine

时光怂恿深爱的人放手 提交于 2019-11-27 13:21:35
So here's what I'm attempting to do. I'm building an ember.js application, with a java backend running on GAE. I'm using handlebars, but I want them divided up into separate files, not just all pasted into the index.html. Via the ember.js irc I was turned on to rake-pipeline along with minispade Along with the web filters and a custom handlebars filter I started building the assetfile. I don't know Ruby, or gem files, etc. So I'm trying to figure out the best way to be able to compile my coffeescript/handlebars files on the fly, minispade them, but keep the individual files accessible while in

Sort Select Options by Value Attribute Using jQuery

六眼飞鱼酱① 提交于 2019-11-27 13:20:47
问题 Well, the title says it all. What I am doing is creating a featured product module. The drop down list of sizes is populated using JSON and I am using handlebars to render the html. I do not have control over the JSON file. I tried sorting the option values by the actual text within the option tags, but I realized that the option values were wrong after that. So now I am trying to sort the options by their value attributes, but haven't figured it out yet. I am trying to do something like this

Positional index in Ember.js collections iteration

邮差的信 提交于 2019-11-27 13:11:32
Is there a way to get positional index during iteration in ember.js? {{#each itemsArray}} {{name}} {{/each}} I'm looking for a way to have something like: {{#each itemsArray}} {{name}} - {{index}}th place. {{/each}} Update: As per the comment by @ebryn the below code works without using a nested view for each item: <script type="text/x-handlebars"> {{#collection contentBinding="App.peopleController"}} Index {{contentIndex}}: {{content.name}} <br /> {{/collection}} </script>​ http://jsfiddle.net/WSwna/14/ Although to have something like adjustedIndex, a nested view would be required. It's old