簡體   English   中英

Ejs 包含不渲染的部分文件

[英]Ejs include partials files not rendering

我正在嘗試在 node.js 項目中使用 ejs。 我已經設法呈現視圖文件(.ejs')並在其中使用.js 數據。 並獲取包含樣式表的所需網頁。 僅在使用部分時出現問題在 customer.ejs 中導入 header.ejs 文件后,我在網頁上獲得了 header.ejs 的確切文本語法。 <%- include("partials/header") %>簡而言之,customer.ejs 正在定位 header 文件並導入它。 但不渲染它

Output

�� <�head> <�link rel="stylesheet" href="/css/style.css"> <�title>Customer<�/title> <�/head> 
Name: abc

我的目錄如下project\public\css\style.scc project\views\partials\header.ejs> project\views\customer.ejs project\app.js我正在使用 Express 我的語法如下

應用程序.js

 app.use(express.static('public'));
 app.set('views', './views');
 app.set('view engine', "views");

客戶.ejs

<html >
<%- include("partials/header") %> 
<body>
    <h1>
         Name: <%= customer.name %>
    </h1>   
    
 </body>
 </html>

header.ejs

<head>

    <link rel="stylesheet" href="/css/style.css">
    
    <title>Customer</title>
</head>

我試過的東西

<%- include partials/header %> <%- include("partials/header") %> <%- include("./partials/header") %> <%- include("partials/header.ejs") %>和其他幾個 .. 也嘗試使用express-partial模塊。 也在不同的瀏覽器上嘗試過。 如果我做錯了什么或使用解密方法,請告訴我任何幫助將不勝感激。 謝謝你。

在谷歌瀏覽了很長時間后,我得到了問題的答案。 Unicode 出了點問題 將以下內容粘貼到根目錄后,問題就解決了。 按下回車鍵后,我的整個 app.js 就變成了一些中文文本。 但是 ctrl+z 把我的代碼帶回來了。

Get-Content .\app.js -Encoding Unicode | Set-Content -Encoding UTF8 
.\app-fixed.js ; Move-Item -Path .\app-fixed.js -Destination .\app.js - 
Confirm -Force 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM