由於某些原因,我無法將變量傳遞給具有Node JS的帕格模板。節點JS將變量傳遞給Jade/Pug
app.get("/", function (req, res) {
res.render('index', { hello : 'Hey'})
})
....
extends layout.pug
block content
h1 #{hello} guy
這只是返回與「哈巴狗index.html文件中
由於某些原因,我無法將變量傳遞給具有Node JS的帕格模板。節點JS將變量傳遞給Jade/Pug
app.get("/", function (req, res) {
res.render('index', { hello : 'Hey'})
})
....
extends layout.pug
block content
h1 #{hello} guy
這只是返回與「哈巴狗index.html文件中
我認爲你正在使用JADE編碼(#{}你好) 「傢伙」 「(更新玉)插件與靜態.html - 完全錯誤。
按照以下線路:
使用這首
app.set('views', __dirname + '/public/views');
app.set('view engine', 'pug');
比這傳遞給第一次訪問
app.get('/', function (req, res) {
res.render('index', { title: 'Hey', message: 'Hello there!'});
});
比在模板文件「index.pug呼應「in」/ public/views「
html
head
title= title
body
h1= message
它仍然沒有工作,一切都是一樣的。 –
給我你的目錄結構的快照 + 顯示我 app.set( '意見',__dirname + '/公/若干意見')的服務器上的文件; app.set('view engine','pug'); ('/',function(req,res){ res.render('index',{title:'Hey',message:'Hello there!'}); ( )通過這個來第一次訪問 }); –
現在它只是說「快遞」https://github.com/jpking72/nodejsfiddle.git –
你可以把更多的代碼?什麼是'應用程序'? 'layout.pug'有什麼? – chharvey