Skip to content

Instantly share code, notes, and snippets.

@gkspranger
Last active May 17, 2017 17:56
Show Gist options
  • Save gkspranger/086593b7c5bb832634dfc8f079fbf9b6 to your computer and use it in GitHub Desktop.
Save gkspranger/086593b7c5bb832634dfc8f079fbf9b6 to your computer and use it in GitHub Desktop.
// Commands:
// hubot handlebar me - example of how to use handlebars
const logger = require("winston");
const handlebars = require("handlebars");
const fs = require("fs");
module.exports = function(robot) {
// this is the controller
robot.respond(/handlebar me/i, function(message) {
// this is me getting the view
fs.readFile('./views/mytemplate.txt', 'utf-8', function(error, source) {
var template = handlebars.compile(source);
// this is me passing the model into the view
var output = template({
line1: "this is line 1",
arr1: [
"this",
"is",
"an",
"array"
],
obj1: {
obj: "object within an object"
}
});
// this is me replying to the hubot command
message.send(output);
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment