위와 같은 구문은 JAVA/JSP를 공부할 때 자주 사용했었기 때문에 꽤나 익숙하다.
// app.js
app.set('view engine', 'ejs');
app.set('views', 'views');
...
// admin.js
res.render("add-product", {
pageTitle: "Add Product",
path: "/admin/add-product"
});
<%- include('includes/shop-head.ejs') %>
</head>
<body>
<%- include('includes/navigation.ejs')%>
<main>
<% if (prods.length > 0) { %>
<div class="grid">
<% for (let product of prods) { %>
<article class="card product-item">
<header class="card__header">
<h1 class="product__title"><%= product.title %></h1>
</header>
<div class="card__image">
<img src="image" alt="A Book">
</div>
<div class="card__content">
<h2 class="product__price">$19.99</h2>
<p class="product__description">A very interesting book about so many even more interesting things!</p>
</div>
<div class="card__actions">
<button class="btn">Add to Cart</button>
</div>
</article>
<% } %>
</div>
<% } else { %>
<h1>Product Not Found!</h1>
<% } %>
</main>
<%- include('includes/end.ejs') %>
<%- include('레이아웃 저장폴더/파일명') %>
<% if(prods.length > 0) { %>
원하는 내용
<% } %> //열었으면 닫아줘야 한다.
<%= prods.title %>