链接到其他玉器文件 [英] Linking to other jade files
问题描述
首先,当我使用layout.jade作为模板时,我正在做正确的事情文件(标题,正文,页脚)和使用不同的文件来显示正文中的信息(见下面的例子)?
代码工作正常,但我不确定这是在Express中做事情的正确方法。如果我应该继续使用这个结构,那我该如何链接到其他的文件(例如.About.jade),例如index.jade,以显示该文件,而不是index.jade? p>
提前感谢!
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')
脚本(type ='text / javascript',src ='http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js')
脚本(type ='text / javascript',src ='/ javascripts /external.js')
//头文件
头文件头
//导航
nav#nav
//导航代码(ul,li等)...
// Sidebar
旁边#sidebar
//边栏代码...
// Body
body!= body
index.jade:
!!! 5
html
head
title = title
section#wrapper
img.imageStyle(src ='/images/test1.png')
//等等...
About.jade:
//你收到...
我想你正在寻找的是在快照中查看渲染路线:
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 ='/ )约
更新此外,您不需要再次重复索引。
!!! 5
html
head
title = title
I'm trying to understand how Express and Jade works.
First of all, am I doing it right when I'm using layout.jade as a template file (header, body, footer) and using different files to show information in the body (see examples below)?
The code works fine, but i'm unsure if this is the right way to do stuff in Express. If I should keep going with this structure, how can I link to other files (eg.About.jade) internally from for example index.jade, to show that file instead of index.jade?
Thanks in advance!
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...
I think what you're looking for are view rendering routes in express: http://expressjs.com/en/guide/using-template-engines.html
So you can set up something like this:
app.get('/', function(req, res){
res.render('index.jade', { title: 'index' });
});
app.get('/about', function(req, res){
res.render('about.jade', { title: 'about' });
});
To link from one to the other, once you have the proper routes configured, you can just do something like:
a(href='/') index
a(href='/about') about
Update Also, you don't need this repeated again in index.
!!! 5
html
head
title= title
这篇关于链接到其他玉器文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!