跳到主要內容

[NodeJS] 網頁應用程式設計 使用 Node 和 Express 筆記

express3-handlebars

這個套件已改名為express-handlebars,所以安裝指令為

$ npm install --save express-handlebars

在app.js中設定︰

// 設定handlebar view引擎
var handlebars = require('express-handlebars')
	.create({defaultLayout:'main'});
app.engine('handlebars', handlebars.engine);
app.set('view engine', 'handlebars');
// 並將副檔名指定為hbs
var handlebars = require('express-handlebars')
	.create({extname:'.hbs', defaultLayout:'main'});
app.engine('hbs', handlebars.engine); // 這裡一定要用hbs!!!
app.set('view engine', 'hbs'); // 這裡一定要用hbs!!!

官網︰https://github.com/ericf/express-handlebars

模擬器︰http://tryhandlebarsjs.com/

另外,http://handlebarsjs.com/ 這個好像是後續版本,但是設定不起來,說明也不清楚…只好by pass~

 

書中建議用handlebars,但實在覺得pug比較好用,所以決定還是用pug

https://pugjs.org/api/getting-started.html

pug to html 工具︰

http://html2pug.com/

 

關於node_modules被commit到git的問題

gitignore︰

https://github.com/github/gitignore/blob/master/Node.gitignore

將已commit的部份移除︰

git rm --cached -r node_modules/

留言