![](/img/trans.png)
[英]How to render html page on certain path from certain directory with node.js express
[英]How to render html into a page but not as the entire view into an Node.js + express app?
意圖
我需要將hmtl的一部分渲染到頁面中。
問題
頁面呈現時沒有樣式或布局。
我有一個頁面,我需要使用純HTML而不是翡翠。 但仍將在其他地方使用玉器。
我遵循了一個類似的問題 ,該問題可以定向到html頁面。 但是如果不傳遞樣式和布局。
我的上一頁是cases.jade
,它是這樣開始的
extends layout
block content
.row
.twelve.columns
h1 title
現在我的新頁面是cases.html
,開始是這樣
<div class="row">
<div class="twelve columns">
<h1>Before & After Case Gallery</h1>
並被路由到這樣
app.get('/cases', function (req, res)
{
res.render('cases.html');
});
並在此之上
app.set('views', __dirname + '/views');
app.engine('html', require('ejs').renderFile);
似乎在您的Jade文件中,您正在擴展布局頁面,因此您包括了所有布局信息。 但是在HTML版本中,您不會導入任何布局信息。
我看到您正在使用ejs 。 查看布局,看看要放入模板中的內容:
<% include head %>
<h1>Title</h1>
<p>My page</p>
<% include foot %>
在這里,您需要對layout.html
布局頁面內容執行類似<%include layout %>
。 include
行基本上會將文件的內容復制粘貼到該位置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.