Skip to content

Instantly share code, notes, and snippets.

@dburles
Created August 22, 2014 08:36
Show Gist options
  • Save dburles/69f080fd6803e52e751c to your computer and use it in GitHub Desktop.
Save dburles/69f080fd6803e52e751c to your computer and use it in GitHub Desktop.
Router.handlebars = function(options) {
options = options || {};
options.data = options.data || {};
if (! options.template)
throw new Meteor.Error("Router.handlebars: options.template is required");
if (! options.path)
throw new Meteor.Error("Router.handlebars: options.path is required");
return {
where: 'server',
path: options.path,
action: function() {
var data = _.isFunction(options.data) ?
options.data() : options.data;
this.response.writeHead(200, { 'Content-Type': 'text/html' });
this.response.end(Handlebars.templates[options.template](data));
}
};
};
Router.map(function() {
this.route('test-handlebars', Router.handlebars({
path: '/test-handlebars',
template: 'test',
data: function() {
return {
test: 'World!'
};
}
}));
});
<h1>Hello {{test}}</h1>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment