handlebars.js

Difference between react.js and Ajax

萝らか妹 提交于 2019-12-03 02:00:02
问题 When I googled about React.js what I got is: React.js is a Framework that is used to create user interfaces. If a particular part of the website is frequently updated that means we can use react. But I am confused that Ajax has been used for this only. We can update a part of site using Ajax without page refresh. For templating we would be using handlebars and mustache. Could somebody explain me in what ways react is different from Ajax and why we should use it. 回答1: Ajax is used to refresh a

NodeJS + Express + Handlebars - failed to locate view “index.html”

筅森魡賤 提交于 2019-12-03 01:52:59
I have been playing a bit with Node.js. I recently started toying with Express and have been setting up a basic app. I wanted to use Handlebars as my view templating engine, but am hitting a wall - failed to locate view "index.html" I have index.html in the same directory as app.js and and so I would think the code below would have no problem locating index.html... I have searched around, but it would seem that comprehensive examples of anything aside from jade are rare... Anyone have experience with this combo? Thanks in advance! var express = require('express') , app = express.createServer()

Precompiled Handlebars templates in Backbone with Requirejs?

浪子不回头ぞ 提交于 2019-12-03 01:51:56
I've been messing around with a backbone.js app using require.js and a handlebars templates (I've added the AMD module stuff to handlebars) and just read that pre-compiling the templates can speed it up a fair bit. I was wondering how I would go about including the precompiled templates with requirejs. I have a fair few templates to compile (upwards of 15), so i'm not sure if they should all be in the same output file or have their own once compiled. Also, from what it seems, the compiled templates share the same Handlebars namespace that the renderer script uses, so I'm not sure how I would

Using variables for a partial template

落花浮王杯 提交于 2019-12-03 01:45:50
I'm definitely missing something about the way Handlebars works. I need to call different partials depending on the value of a variable. Currently the only way I've found to do it is this: <template name="base"> {{#if a}}{{> a}}{{/if}} {{#if b}}{{> b}}{{/if}} {{#if c}}{{> c}}{{/if}} </template> And in the corresponding JS: Template.base.a = function () { return (mode === "a"); } Template.base.b = function () { return (mode === "b"); } Template.base.c = function () { return (mode === "c"); } ...which strikes me as extremely verbose. What I'd really like to do is something like: <template name=

loading handlebars template asynchronously

做~自己de王妃 提交于 2019-12-03 01:32:47
I'm trying to write a function that will give me a compiled handlebars template (I have all my templates in separate files) using an ajax call to get the template and compile it for use, but I need to use a promise so I can actually use it. function getTemplate(name){ $.get('/'+name+'.hbs').success(function(src){ var template = Handlebars.compile(src); //can't return the template here. }); } How do I do this with promises so I can do something like: $("a").click(function(e){ getTemplate('form').done(function(template){ $("body").append(template({ name: "My Name" }) ); }); }); Chovy, I see you

How to change default layout in express using handlebars?

被刻印的时光 ゝ 提交于 2019-12-03 00:59:04
问题 I am using Express 4.9.0 and express-generator. Created boilerplate with a following command: express --hbs projectname Builtin handlebars is using views/layout.hbs by default as a master page. But i cannot see any settings in my app.js to change that behaviour. piece of code from my app.js: // view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'hbs'); How can i change my default layout globally? What if i want to have 2 or 3 different global layouts?

Ember.js - doing it right (structure, includes, general questions)

五迷三道 提交于 2019-12-03 00:40:25
I'm playing around with ember.js and am stuck somehow finding out how to build up the structure the right way. I could follow all examples , but have some problems putting them all together. I'm using require.js and handlebars. My directory structure looks like this: - app - - controllers - - css - - helpers - - lib - - models - - routes - - templates - - - partials - - views My application.js looks like this: require.config({ paths:{ jquery:'lib/jquery-1.7.2', handlebars:'lib/handlebars', ember:'lib/ember', ember_data:'lib/ember-data', text:'lib/requireJS/text', md5:'lib/md5', spin:'lib/spin'

Dynamically choosing a view at runtime with Ember + Handlebars

非 Y 不嫁゛ 提交于 2019-12-03 00:39:23
I am using Ember, Ember Data, and Handlebars to display a timeline with a number of different types of models. My current implementation, though functioning properly, seems like it could be drastically improved with a convention and a helper. However, I can't figure out how to use already defined templates. This is what I have: {{#view App.AccountSelectedView contentBinding="App.selectedAccountController.everythingSorted"}} {{#with content}} <ol class="timeline"> {{#each this}} {{#is constructor="App.Design"}} ... stuff about the design {{/is}} {{#is constructor="App.Order"}} ... stuff about

How to use templating (handlebars, or any alternative) with Node.js and without using a framework (ex = express)?

南笙酒味 提交于 2019-12-02 23:11:25
For example, I have this JSON document "foo.json": { "foo": [ { "bar": "Hello World!" }, { "bar": "The End" } ] } In Node.js, I would like to use templating (handlebars or any) to generate a string from the JSON document, such as: <p>Hello World!</p><p>The End</p> ... And then assign that string value to a variable in Node.js. Finally, I'll concatenate more values to the variable and output the final variable value as an html document. Can this be done without using a framework like Express? If you want to use handlebars, just grab the npm module: npm install handlebars Then in your script,

Counter for handlebars #each

我是研究僧i 提交于 2019-12-02 22:46:52
In Handlebars, say i have a collection of names how can i do {{#each names}} {{position}} {{name}} {{/each}} where {{position}} is 1 for the first name, 2 for the second name etc. Do I absolutely have to store the position as a key in the collection? You can do this with the built-in Handlebars @index notation: {{#each array}} {{@index}}: {{this}} {{/each}} @index will give the (zero-based) index of each item in the given array. Please note for people using Handlebars with the Razor view engine you must use the notation @@index to avoid compilation errors. For more built-in helpers see http:/