-
-
Save hostsamurai/5036107 to your computer and use it in GitHub Desktop.
consolidate.js lets you specify partials in your render functions. The gist assumes you have index.html and partial.html inside of your views folder.
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
/*jslint node: true */ | |
"use strict"; | |
var express = require("express"), | |
consolidate = require("consolidate"), | |
Handlebars = require("handlebars"), | |
fs = require("fs"); | |
var app = express(); | |
// Configure the Handlebars engine | |
app.engine("html", consolidate.handlebars); | |
app.set("view engine", "html"); | |
app.set("views", __dirname + "/views"); | |
// Define a route that renders the index view | |
app.get("/", function (req, res) { | |
res.render("index", { | |
hello: "Hello", | |
world: "World", | |
partials: { | |
partial: 'partial' // maps to views/partial.html | |
} | |
}); | |
}); | |
app.listen(3000); |
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
<html> | |
<head> | |
<title>Index</title> | |
</head> | |
<body> | |
<p>{{ hello }}</p> | |
{{> partial }} | |
</body> | |
</html> |
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
<p>{{ world }}!</p> |
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
{ | |
"name": "express-and-handlebars", | |
"version": "0.0.0", | |
"main": "app.js", | |
"dependencies": { | |
"express": "3.x", | |
"consolidate": "0.8.0", | |
"handlebars": "1.0.9" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment