Skip to content

Instantly share code, notes, and snippets.

@hostsamurai
Forked from eliOcs/apps.js
Last active December 14, 2015 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hostsamurai/5036107 to your computer and use it in GitHub Desktop.
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.
/*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);
<html>
<head>
<title>Index</title>
</head>
<body>
<p>{{ hello }}</p>
{{> partial }}
</body>
</html>
<p>{{ world }}!</p>
{
"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