Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Servlet
- node.js
- 반응형 페이지
- git
- redux
- cleancode
- 코딩테스트
- 자바
- JavaScript
- 그럼에도 불구하고
- 자바문제풀이
- webpack
- max-width
- frontend
- github
- media query
- react-router-dom
- HTML
- 코드업
- coding
- node
- @media
- CSS
- 변수
- JS
- 그럼에도불구하고
- java
- react
- 프론트엔드
- TypeScript
Archives
- Today
- Total
그럼에도 불구하고
[Png] Pug layout 만들기 본문
Pug를 이용하여 공통된 layout을 만들어보자
shop.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Shop</title> <link rel="stylesheet" href="/css/main.css"> </head> <body> <header class="main-header"> <nav class="main-header__nav"> <ul class="main-header__item-list"> <li class="main-header__item"><a class="active" href="/">Shop</a></li> <li class="main-header__item"><a href="/admin/add-product">Add Product</a></li> </ul> </nav> </header> <main> <h1>My Products</h1> <p>List of all the products...</p> </main> </body> </html> | cs |
add-product.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Add Product</title> <link rel="stylesheet" href="/css/product.css"> <link rel="stylesheet" href="/css/forms.css"> <link rel="stylesheet" href="/css/main.css"> </head> <body> <header class="main-header"> <nav class="main-header__nav"> <ul class="main-header__item-list"> <li class="main-header__item"><a href="/">Shop</a></li> <li class="main-header__item"><a class="active" href="/admin/add-product">Add Product</a></li> </ul> </nav> </header> <main> <form class="product-form" action="/admin/add-product" method="POST"> <div class="form-control"> <label for="title">Title</label> <input type="text" name="title" id="title"> </div> <button class="btn" type="submit">Add Product</button> </form> </main> </body> </html> | cs |
404.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>404 Error</title> <link rel="stylesheet" href="/css/main.css"> </head> <body> <header class="main-header"> <nav class="main-header__nav"> <ul class="main-header__item-list"> <li class="main-header__item"><a href="/">Shop</as=></li> <li class="main-header__item"><a href="/admin/add-product">Add Product</a></li> </ul> </nav> </header> <h1>Page Not Found</h1> </body> </html> | cs |
위 3개의 html에는 공통된 부분을 main-layout.pug로 변환해 보자
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | doctype html html(lang="en") head meta(charset="UTF-8") meta(http-equiv="X-UA-Compatible", content="IE=edge") meta(name="viewport", content="width=device-width, initial-scale=1.0") title #{pageTitle} link(rel="stylesheet", href="/css/main.css") block styles body header.main-header nav.main-header__nav ul.main-header__item-list li.main-header__item a(href="/" class = (path === '/' ? 'active' : '')) Shop li.main-header__item a(href="/admin/add-product" class = (path === '/admin/add-product' ? 'active' : '')) Add Product block content | cs |
위와 같이 공통된 부분을 하나의 파일로 저장해두면 다른 png 파일에서 이를 extends 하여 사용할 수 있다.
title의 경우 #{pageTitle}과 같이 동적 렌더링을 위해 각각의 js 파일에 랜더링을 위한 pageTitle 키와 값을 설정해줘야 한다.
app.js
admin.js
shop.js
block styles 과 block content의 경우 다른 png 파일에서 바뀔 수 있는 부분을 지정한 것이다.
block styles : css 지정
block content : html안에서 상이한 내용을 지정
shop.pug
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | extends layouts/main-layout.pug block styles link(rel="stylesheet", href="/css/product.css") block content main if prods.length > 0 .grid each product in prods article.card.product-item header.card__header h1.product__title #{product.title} div.card__image img(src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBw8PDw8NDQ0NDQ0NDQ0NDQ0NDw8NDQ0NFREWFhURFRUYHSggGBolGxUVITEhJSkrLi4uFx8zODMtNygtLisBCgoKDg0OFQ8QFSsdFR0uLSsrKy0rKy0tKy0tKysrMCstLS0rLS0rLSstKy0rLS0rLTctLS0tLTctKy0tLTc3K//AABEIALsBDQMBIgACEQEDEQH/xAAcAAACAgMBAQAAAAAAAAAAAAABAgADBQYHBAj/xABJEAACAQIBBA0JBQYEBwAAAAAAAQIDEQQFEiExBgcTQVFSU3GBkZLB0SIyVGGCk6Gx0hQVFnLCF0SDorLhYmOj8CMkNEJDc8P/xAAYAQEBAQEBAAAAAAAAAAAAAAAAAQIDBP/EACkRAQEAAgEDAwMDBQAAAAAAAAABAhESAzFRMkFhInGxIYHBIzNCkfD/2gAMAwEAAhEDEQA/AOjoZCoY0CggQQCG64UVx06bD2OXNrRk1woOcuFdYqQbDnU0bOXCHOXCLYlhzq6PnLhJnLhQtiWHOmj39YSpoDXBo5hz+DS4hRukl6+caNdPQ9D+BqZyppaQjZU663tPNqLbIi0hTurfAviS74fkZ5xdLiFOnhfWSz4X1sc/hdLgFNvW+tgs+F9bHP4NLiFGnhfWC74WOaaXgKc+XD8EDdJcPwHOHFcKVKvZpSsk9F9WktuamUpZoGBhYDSFYGMwAKhkKhkAUCcrJ9XXoNO2zst4jB4ajLCVdxnVxG5ykowlLMzJPRnJ20pFmw+WIlRoVcViquJqV4wrPPsowTWcoqKS638DnlnpudP6eW23Q1dY6FhqHRiJUCKQ1pNmuG4gUXRs9yXAiWGjYisIGTRskkVSiWyEJYsquKk5NOTcVGNo6LJ3enh4OoujEEV5T/LH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Eq2/h+JFlqPotX/T8Rs4Xw7n9vo8vS95HxB9uo8tS7cfE4d99xvb7LUvq10/EP36l+7Vf9PxGzhfDt/26jy1Ltx8QPHUeWpduPicSWyBej1eun4jrZHwUK3XT8Rs4Xw7S8dR5al24+Irx9HlqXbj4nGVsoa/8Vbrp+Iy2WS5Kr0un4k2vC+HYJYiE35E4TtGSeZJStwXtzGNqvScyjsxnHTGNaL06VKmn13PVh9n0lZVKMprjOUIyt16SLwy8NlyZLMy5blsDLpalH6Wb9c5LkjL0MVlfBVKcJQajWpTTcZZy3ObVrdJ1dM3h2TqzVn2ePFUI1ac6U75lSE6cknZ5sk0/gzUntc4PlMUvbhq7JuKIbslYmVnatLntaYKWupie1B/pKv2XYLlcT2ofSb0FE1Dlb7tFW1fguVxPah9JFtYYHlMR2ofSb2SxdROV8tFW1lgeUxHah9Iy2tMDx8R2qf0m7hQ1DlfLSltaYHj4jtQ+kZbW2C4+I7UPpN0GQ1DlfLS/wBm2B42I7UPpD+zfBcfEduP0m6EQ1Dll5aZ+zfBcfEduPgH9m2C4+I7cfA3Qg1DlfLS1tbYDfliGt9borP4Fq2t8l8hUfrdapf5m4EGocr5amtrvJVv+k6d1rX/AKiyO1/ktX/5TX/m1mlo3vKNoINJyvlrC2A5NvdYdresqtVL5jrYNk70Z9NWr9RsxGNRd3y1lbB8m+ir3lX6hlsKyav3SPbqeJsbANQ3fLX1sMyd6HT7U/EK2HZO9Co/zPvM+yA3WDWxPJ9rfYqHZuT8KZP9Bw/u0ZtgYN1hvwvk/wBBw3uoh/DGA9BwvuoeBl2AG6xS2OYFfuWF9zT8A/h/BehYX3NPwMoAJtjvuTCb2Ew3uafgBZGwu9hcP7mn4GQIB5sPgKNN50KNKD4YQjF9aR67gAB//9k=", alt="A Book") div.card__content h2.product__price $19.99 p.product__description A very interesting book about so many even more interesting things! .card__actions button.btn Add to Cart else h1 No Products | cs |
add-product.pug
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | extends layouts/main-layout.pug block styles link(rel="stylesheet", href="/css/product.css") link(rel="stylesheet" href="/css/forms.css") block content main form.product-form(action="/admin/add-product" method="POST") div.form-control label(for="title") Title input(type="text" name="title")#title button.btn(type="submit") Add Product | cs |
404.pug
1 2 3 4 | extends layouts/main-layout.pug block content h1 Page not Found! | cs |
'Node.js > Template engines' 카테고리의 다른 글
[EJS] EJS에 대해 알아보자 (0) | 2023.02.09 |
---|---|
[Png] 동적 콘텐츠 출력 (0) | 2023.02.08 |
[Png] Pug에 대해 알아보자 (0) | 2023.02.08 |
Comments