Created
August 22, 2014 08:36
-
-
Save dburles/69f080fd6803e52e751c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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