Skip to content

Instantly share code, notes, and snippets.

@sukobuto
Created January 31, 2014 07:56
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 sukobuto/8728113 to your computer and use it in GitHub Desktop.
Save sukobuto/8728113 to your computer and use it in GitHub Desktop.
【爆速テンプレートエンジン】Express3 以降で layout.ejs が使えなくなった代わりに ECT ref: http://qiita.com/sukobuto/items/b0be22bfebd721854e0b
/**
* Module 読み込み
*/
var express = require('express');
var routes = require('./routes');
var user = require('./routes/user');
var http = require('http');
var path = require('path');
var ECT = require('ect'); // ECT 読み込み
var app = module.exports = express();
app.set('port', process.env.PORT || 3000);
// ECT 環境設定
app.engine('ect', ECT({ watch: true, root: __dirname + '/views', ext: '.ect' }).render);
app.set('view engine', 'ect');
// その他 環境設定
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(express.cookieParser('your secret here'));
app.use(express.session());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', routes.index);
http.createServer(app).listen(app.get('port'), function() {
console.log('Express server listening on port ' + app.get('port'));
});
<% extend 'layout' %>
<h1><%= @title %><h1>
/*
* GET home page.
*/
exports.index = function (req, res) {
res.render('index', { title: 'Hello, ECT!' });
};
<!DOCTYPE html>
<html>
<head>
<title>Express3 + ECT</title>
<link rel='stylesheet' href='/stylesheets/style.css' />
</head>
<body>
<% content %>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<link rel='stylesheet' href='/stylesheets/style.css' />
</head>
<body>
<%- body %>
</body>
</html>
[user@host project]$ npm install ect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment