Layout 생성하기

layout.hbs

<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="public/css/style.css" />
    <title>Document</title>
  </head>
  <body>
    <h1>{{imageTitle}}</h1>
    {{{body}}}
  </body>
</html>

index.hbs

<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="public/css/style.css" />
    <title>Document</title>
  </head>
  <body>
    <h1>{{imageTitle}}</h1>
    <img src="public/images/profile.png" alt="profile" />
  </body>
</html>

posts.hbs

<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="public/css/style.css" />
    <title>Document</title>
  </head>
  <body>
    <p>It is a {{templateName}} template</p>
  </body>
</html>

controllers/posts.controller.js

const path = require("path");

function getPost(req, res) {
  res.render("posts", { templateName: "post" });
}

module.exports = { getPost };