Skip to content

Instantly share code, notes, and snippets.

@yurfuwa-chan
Last active December 10, 2015 22:09
Show Gist options
  • Save yurfuwa-chan/4500257 to your computer and use it in GitHub Desktop.
Save yurfuwa-chan/4500257 to your computer and use it in GitHub Desktop.
express + ejs + express-partial
var express = require('express');
var http = require('http');
var partials = require('express-partials');
var app = express();
var server = http.createServer(app);
var path = require('path');
var ejs = require('ejs');
app.configure(function(){
app.use(partials());
app.use(express.favicon());
app.set('view engine','ejs');
app.set('view options',{layout:false});
app.set('views',__dirname+'/views');
//publicパス設定。
app.use(express.static(path.join(__dirname, 'public')));
});
// localhost:3000/10000
// な感じでアクセスするとそれに応じてテンプレート差し替える
app.get('/:id',function(req,res){
res.render('layout.ejs',{id:""+req.params.id});
})
app.listen(3000)
<body>
<%- partial('header') %>
<%- partial(id) %>
<%- partial('footer') %>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment