nodejs视图不会在布局中显示

我正在尝试使用CoffeeScript,NodeJS和expressJS创build一个简单的布局。 我的咖啡脚本是

routes.coffee我已经将路由文件夹重命名为应用程序,而我的routes.coffee文件位于身份validation文件夹中,例如apps\authentication\routes.coffee

 routes = (app) -> app.get "/login", (req , res) -> res.render "#{__dirname}/views/login", title: 'Login', stylesheet: 'login' module.exports = routes 

login视图我已经更名为path文件夹应用程序和我的login视图在那里authentication文件夹,即apps\authentication\views\login.jade

 extends ../../../views/layout block content form(action='/sessions', method='post') label | Username input(type='text', name='user') label | Password input(type='password', name='password') input(type='submit', name='Submit') 

Layout.jade这个文件在默认视图文件夹中。 我正在使用默认布局

 doctype html head title= title body #content h1= title block content != body 

app.js

 require('coffee-script').register(); var express = require('express'); var path = require('path'); var favicon = require('serve-favicon'); var logger = require('morgan'); var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser'); //var index = require('./routes/index'); //var users = require('./routes/users'); var app = express(); // view engine setup // app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade'); // app.set('view options', { layout: 'views/layout' }); // uncomment after placing your favicon in /public app.use(favicon(path.join(__dirname, '/public', 'favicon.ico'))); app.use(logger('dev')); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); app.use(cookieParser()); app.use(express.static(path.join(__dirname, '/public'))); // app.use(express.static('public')); app.set('view options', { layout: false }); //app.use('/', index); //app.use('/users', users); require('./apps/authentication/routes')(app); // catch 404 and forward to error handler app.use(function(req, res, next) { var err = new Error('Not Found'); err.status = 404; next(err); }); // error handler app.use(function(err, req, res, next) { // set locals, only providing error in development res.locals.message = err.message; res.locals.error = req.app.get('env') === 'development' ? err : {}; // render the error page res.status(err.status || 500); res.render('error'); }); module.exports = app; 

我在layout.jade创build了两个variablestitlestylesheet ,但是当我尝试在layout.jade即title中实现这些variables时,我在标题中得到了undefined的标题。

任何人都可以帮忙吗?

谢谢。

       

网上收集的解决方案 "nodejs视图不会在布局中显示"

我想你没有正确使用缩进。 在您的login视图中:

 extends ../../../views/layout block content form(action='/sessions', method='post') label | Username input(type='text', name='user') label | Password input(type='password', name='password') input(type='submit', name='Submit') 

应该 :

 extends ../../../views/layout block content form(action='/sessions', method='post') label | Username input(type='text', name='user') label | Password input(type='password', name='password') input(type='submit', name='Submit')