0

理解できれば、Jadeを使用するときに、テンプレートの一部を親テンプレートに移動できますか?

いくつかのjsファイルへのリンクをヘッドセクションに移動しようとしました。これはWebサイトの一部でのみ使用していますが、エラーが発生します。

私のlayout.jade:

!!!
html(lang='en')
  head
    title= title
    link(rel='stylesheet', href='/stylesheets/box.css')
    block scripts
  body
    ..

私のindex.jade(試してみるだけで、他のファイルにあります)

extends layout

block scripts
  script(src='myscriptfile.js')
div#sortable
  ..

およびノー​​ドサーバーの一部:

app.get('/', function(req, res){
  res.render('index', 
    {title: 'My title',
    images: images}
  );
});

このオプションをtrue/falseに切り替えます

app.set('view options', { pretty: true });

しかし、それでもエラーが発生します:

Express
500 ReferenceError: E:\projekt/views/index.jade:13 11| 12| > 13| 14| body is not defined

私は何が間違っているのですか?

4

1 に答える 1

2

In the .. of your snippets, you're referencing a body variable that hasn't been defined. I'm guessing around line 13 of index.jade:

500 ReferenceError: E:\projekt/views/index.jade:13 11| 12| > 13| 14| ...

You'll either have to remove it from the view or define it in the view data:

res.render('index', 
    {title: 'My title',
    images: images,
    body: '...'}
);

Side note:

If you haven't upgraded to Express 3.x, you may want to ensure layouts are disabled:

app.set('view options', {
  layout: false,
  pretty: true
});

Inheritance and blocks are meant to replace layouts, not work with them. As stated in Migrating from 2.x to 3.x:

Removed... the concept of a "layout" (template engine specific now)

于 2012-05-30T21:30:18.120 に答える