본문 바로가기

컴퓨터/NodeJS

NodeJS ejs-locals

설치
npm install ejs-locals
설정
const engine = require('ejs-locals');

app.engine('ejs', engine);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
사용

layout.ejs

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" href="/public/styles/index.css">
    <%-stylesheets%>
    <title>타이틀</title>
  </head>
  <body>
    <nav>
      <a href="/"><button>홈</button></a>
<% menus.forEach(function(menu) { %>
      <a href="<%= menu.url %>"><button><%= menu.name %></button></a>
<% }) %>
    </nav>
    <hr>
    <section>
      <%-body -%>
    </section>
    <script src="/public/scripts/fetch.js"></script>
    <%-scripts%>
  </body>
</html>

page.ejs

<% layout('layout') -%>
<link rel="stylesheet" href="/public/styles/designRights.css">
<p>Hello, World!</p>
<% script('/public/scripts/page.js') -%>

'컴퓨터 > NodeJS' 카테고리의 다른 글

모든 뷰에 데이터 전송  (0) 2023.06.02
NodeJS obfuscator 코드의 최소화, 난독화  (0) 2023.05.27
Nodejs nodemon  (0) 2023.04.28
NodeJS crypto 암호화 복호화  (0) 2022.07.25
NodeJS cors  (0) 2022.07.06