2012-06-01 2 views
0

좋아요. 따라서 확장/차단 키워드로 작업 할 수있는 템플릿을 가져 오는 데 문제가 있습니다. 색인 템플릿을 정상적으로 작동시킬 수있었습니다. 그러나 두 번째 템플릿을 추가하려고하면 '확장'이 작동하지 않는 것 같습니다. 아래에 코드를 붙여 넣었고 도움을 주시면 감사하겠습니다!jade는 express.js에서 키워드 문제를 확장합니다.

var express = require('express') 
    , routes = require('./routes'); 

var app = module.exports = express.createServer(); 

// Configuration 

app.configure(function(){ 
    app.set('views', __dirname + '/views'); 
    app.set('view engine', 'jade'); 
    app.use(express.bodyParser()); 
    app.use(express.methodOverride()); 
    app.use(express.cookieParser()); 
    app.use(express.session({ secret: 'your secret here' })); 
    app.use(app.router); 
    app.use(express.static(__dirname + '/public')); 
    app.set('view options', { layout: false, pretty: true }); 
}); 

app.configure('development', function(){ 
    app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); 
}); 

app.configure('production', function(){ 
    app.use(express.errorHandler()); 
}); 

// Routes 

app.get('/', routes.index); 
app.get('/login', routes.login); 

app.listen(3000, function(){ 
    console.log("Express server listening on port %d in %s mode", app.address().port,  app.settings.env); 
}); 

루트 /하는 index.js :

app.js (참조, 내가 표현 버전 2.5.8 및 노드 0.6.12 실행하고) 관점에서

exports.index = function(req, res){ 
    res.render('index', { title: 'rm-dash-r' }) 
}; 

exports.login = function (req, res) { 
    res.render('login', { title: 'rm-dash-r' }) 
}; 

를/디렉토리에는 3 개의 파일이 있습니다. index.jade, main-layout.jade 및 login.jade가 있습니다. 테스트를 위해 로그인과 색인은 동일한 파일입니다.

메인 layout.jade :

!!! 
html 
    head 
    title= title 
    link(rel='stylesheet', href='/stylesheets/style.css') 
    body(style='margin: 0 22%;') 
    div.container 
     div.header 
      a(href='/') 
       span rm-dash-r 

     div.stripes 
      span 

     div.nav 
      a(href='/') Blog 
      a(href='/') About 
      a(href='/') Projects 
      div.clearer 
       span 

     div.stripes 
      span 

     div.main 
      div.left 
       div.content 

        block content 
... 

index.jade/login.jade :

extends main-layout 

block content 
    h1 testing 

본질적으로의 경로가 '/'아무 문제없이 작동하지만 로그인 경로 것 페이지 위쪽의 main-layout 확장을 제외하고는 login.jade 마크 업만 렌더링합니다.

알아두면 도움이되는 다른 정보가 있으면 알려 주시기 바랍니다.

+0

코드를 실행했지만 사용자가 말하는 오류를 재연하지 못했습니다. 콘텐츠 블록 이후 메인 레이아웃에 다른 것이 있습니까? 그렇다면 출력물을 제거하고 출력물이 다른지 확인하십시오. – tUrG0n

+0

나중에 코드를 제거하려고했지만 여전히 동일한 문제가 발생합니다. /와/login 경로를 모두 제대로 작동시킬 수 있었습니까? 어떤 express/node/jade 버전이 시스템에 있습니까? 감사. – ebensing

+0

비취 : 0.21.0 | 노드 v0.6.18 | express : 2.5.8 ... 코드가 온라인에서 호스팅 되나요? 그렇지 않다면, 나는 github에서 하나를 만들려고 노력할 것입니다. – tUrG0n

답변

0

상당한 시행 착오 끝에 괜찮습니다. 어떤 이유로, login.jade의 첫 번째 라인에 리턴을 추가 한 후 (즉, main-layout을 확장하면 이제 2 행이됩니다) 모두 작동하는 것처럼 보입니다.

나는 이것이 왜 그런지는 전혀 생각하지 못했지만 누군가가 약간의 빛을 비출 수 있다면 나는 듣고 싶어 할 것입니다.

관련 문제