链接到其他玉石文件(Linking to other jade files)

2019-07-28 22:21发布

我想了解Express和翡翠是如何工作的。

首先,我在做是正确的,当我使用layout.jade为模板文件(头,体,尾),并使用不同的文件显示在体内的信息(见下面的例子)?

该代码工作正常,但我不能确定这是否是做的东西,在快递的正确途径。 如果我要保持这种结构去,我怎么可以链接到其他文件(eg.About.jade)从例如index.jade内部,表明文件,而不是index.jade?

提前致谢!

layout.jade:

!!! 5
html
  head
    title= title
    link(rel='stylesheet', href='/stylesheets/style.css')
    script(type='text/javascript', src='https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js')
    script(type='text/javascript', src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js')
    script(type='text/javascript', src='/javascripts/external.js')

  // Header
  header#header

  // Navigation
  nav#nav
    // Navigation code (ul, li etc)...

  // Sidebar
  aside#sidebar
    // Sidebar code...

  // Body
  body!= body

index.jade:

!!! 5
html
  head
    title= title

    section#wrapper
      img.imageStyle(src = '/images/test1.png')
      // And so on...

About.jade:

// You get it...

Answer 1:

我想你要查找的内容呈现在明确路线图: http://expressjs.com/en/guide/using-template-engines.html

所以,你可以设置是这样的:

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

app.get('/about', function(req, res){
  res.render('about.jade', { title: 'about' });
});

从一个链接到其他,一旦你配置正确的路线,你可以这样做:

a(href='/') index

a(href='/about') about

同时更新 ,你不需要这个指数中再次重复。

!!! 5
html
  head
    title= title


Answer 2:

另外什么韦斯·弗里曼写道,你还可以在您的玉石文件其他玉石模板。

这样你可以有你的header.jade,footer.jade并在您about.jade文件。 这里是从玉石包括文档: https://github.com/visionmedia/jade#a13

如果添加例如脚本或样式表标签,应该是每一个页面上的方式,你只需要改变header.jade文件。



文章来源: Linking to other jade files