본문 바로가기
Node.js/Node

Nunjucks - View Engine

by 김긍수 2020. 12. 21.

여러 템플릿 엔진

expressjs.com/en/resources/template-engines.html

 

Template Engines

Template engines Warning: The packages listed below may be outdated, no longer maintained or even broken. Listing here does not constitute an endorsement or recommendation from the Expressjs project team. Use at your own risk. These template engines work

expressjs.com

 

1. 설치

 

2. Nunjucks 셋팅

app.js파일

autoescape는 xss공격을 방지하기위해 html태그로 입력된 text를 무효화한다. 

false로 설정할 경우에는 html태그가 모두 동작하게 된다.

 

true로 해놨는데, html태그를 뿌려줘야할 경우

products.html파일에 message | safe  를 추가해주면 html태그가 동작한다.

 

 

3. admin/products 라는 url의 템플릿은 템플릿폴더명/admin/products.html 로 생성

4. render() 사용

 

5. 템플릿을 수정하더라도 nodemun에서 바로바로 반영할 수 있도록 설정하는 법

package.json스크립트 부분에 nodemon -e js,html app.js로 수정한다.

 

'Node.js > Node' 카테고리의 다른 글

morgan - 사용자가 어떤 url을 호출했는지 알 수 있는 방법  (0) 2020.12.21
템플릿상속  (0) 2020.12.21
node express 시작  (0) 2020.12.21
nodemon 설치  (0) 2020.12.21
npm  (0) 2020.12.21

댓글