Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix node.js support #90

Closed
wants to merge 2 commits into from
Closed

Fix node.js support #90

wants to merge 2 commits into from

Conversation

jcohen
Copy link

@jcohen jcohen commented May 31, 2011

This addresses #53

The node.js support in handlebars today doesn't seem to work (unless I'm missing something). Primarily the issue is that it's not using relative paths when requiring. Additionally I added a package.json to allow handlebars to be published as an NPM module. If you guys accept this pull request, then publishing the npm package is simply a matter of:

First, create a user account with npm adduser. Give it a username, password, and email address, and it'll create an account on the npm registry. (You can also use adduser to authorize a user account on a new machine, or fix the situation if you break your configs.)

Next, go to the root of your package code, and do npm publish.

(http://howtonode.org/introduction-to-npm)

Thanks!

Joshua

Joshua Cohen and others added 2 commits May 31, 2011 14:13
…ation to prepublish, rather than preinstall to remove the jison dependency for normal users
@benatkin
Copy link

Please just publish this to npm yourself! You can always add wycats, and even remove yourself, later on, thanks to the magic of npm.

@nalanj
Copy link
Contributor

nalanj commented Sep 2, 2011

We've got a package up now. Thanks!

@nalanj nalanj closed this Sep 2, 2011
@trentm
Copy link

trentm commented Nov 19, 2011

To prevent others from flailing embarrassingly long (like I did) to get this going:

$ npm install handlebars
$ node
> var Handlebars = require('handlebars');
> var template = Handlebars.compile("Hi, {{name}}");
> console.log(template({name: "Bob"}));
Hi, Bob

@nuria
Copy link

nuria commented Dec 27, 2011

Since trentm comment was pretty helpful, here is mine. Got node to use precompiled templates by simply including them using requires. For example:

global.Handlebars = require('handlebars');
//these are the precompiled templates
require('./handlebars_small_template_template.js');//defines Handlebars.templates['handlebars_small_template.html']

var small_template_data = {title: "My New Post", body: "This is my first post!................................"};

var small_template = Handlebars.templates['handlebars_small_template.html'];

canvas = Handlebars.templates'handlebars_small_template.html';

rendered_text += canvas;

console.log(rendered_text);

@EntitySpaces
Copy link

I'm confused, was this pull request integrated with handlebars.js, ie, can we run handlebar tempaltes on the server under node.js? Is there a full server side example anywhere, I've been searching and haven't really found one. Unless that is trentm's post above is the answer. I'm kind of new to node.js and want to be able to use Handlebars under it on the server.

@nuria
Copy link

nuria commented May 21, 2012

I have updated my comment above, looks like the bottom of the example was missing.

@FissionCat
Copy link

For anyone else who found this page like I did and was still confused as to how to get server-side templates working without pre-compiling them, I've build upon trentm's example and stuck my code here. Hope this helps someone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants