2016-07-26 85 views
0

我跟着本教程sctoch.io使用ejs文件,但我正在尋找包括當前頁面的主索引。節點js .ejs文件主索引

在教程中,我們將在所有新聞頁面中添加頭部,頁眉和頁腳。

但我想寫一次。例如:

<html lang="en"> 
<head> 
    <% include ../partials/head %> 
</head> 
<body class="container"> 

    <header> 
     <% include ../partials/header %> 
    </header> 

    <main> 
     <!-- Here is that I want --> 
     <% include ../partials/main %> 
    </main> 

    <footer> 
     <% include ../partials/footer %> 
    </footer> 

</body> 
</html> 

當我在我的導航欄的不同鏈接上點擊時,如何在主文件中加載好的頁面?

回答

0

你將不得不使用Express和他的模板引擎(視圖),所以只需添加頁眉和頁腳在每個新文件做

<% include header %> 

<!-- yout html code --> 

<% include footer %> 

當你渲染它簡單地說

第一
res.render('YourNewFile'); 

你的頭應該是這個樣子..

<!doctype html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <meta name="viewport" content="width=device-width"> 
    <title><%- title %></title> 
    <link rel="stylesheet" href="/css/style.css"> 
</head> 
<body> 

和頁腳..just關閉所有標籤..並加載一些腳本,如果你想在它裏面

<script src="..."></script> 
</body> 
</html>