简体   繁体   中英

Ejs include partials files not rendering

I am trying to use ejs in a node.js project. I have managed to render the views file(.ejs') and use the.js data in it. and getting the desired webpage including the stylesheet. the problem occurs only while using partial After importing the header.ejs file in customer.ejs I am getting the exact text syntax of the header.ejs on the webpage. <%- include("partials/header") %> In short customer.ejs is locating the header file and importing the it fine. but not rendering it

Output

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

my directories are as follows project\public\css\style.scc project\views\partials\header.ejs> project\views\customer.ejs project\app.js i am using Express my syntax are as follows

app.js

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

customer.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>

Things i tried

<%- include partials/header %> <%- include("partials/header") %> <%- include("./partials/header") %> <%- include("partials/header.ejs") %> and several more.. also tried using the express-partial module. also tried it on different browsers. Please let me know if i am doing something wrong or using a decrypted method Any help would be appreciated. Thank you.

I got the answer to my question after surfing google for a significant amount of time. Something went wrong with the Unicode After pasting the following in the root dir the problem was solved. Just after hitting enter, my entire app.js got changed to some Chinese text. but ctrl+z brought my code back.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM