Last active
December 10, 2015 22:09
-
-
Save yurfuwa-chan/4500257 to your computer and use it in GitHub Desktop.
express + ejs + express-partial
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
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) |
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
<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