[Node.js] Express에서 기본 Jade 템플릿 형식을 Html로 바꾸기

(Change the template system from Jade to HTML with Express)



 처음 express 를 통해 프로젝트 디렉토리를 만들경우 기본 템플릿 형식입니다.

Jade 를 처음 접하거나 쓰기 어려워하는 분들은 HTML 을 사용하고자 하는데 간단하게 기본 템플릿 형식을 바꾸는 방법이 있습니다.


출처 : https://ademirgabardo.wordpress.com/2016/03/04/how-to-change-the-template-system-from-jade-to-html-with-express/



This quick post is just to remember how to change the template engine on Express from Jade to HTML.

  1. Install the ejs view engine with the NPM:
    npm install ejs
  2. Set your template engine in app.js (or in your custom .js app file) as ejs
    app.engine('html', require('ejs').renderFile);
    app.set('view engine', 'html');
  3. In the route file ./routes/index.js  assign template variables like this
    exports.index = function(req, res){
    res.render('index', { title: 'Page title' });};
  4. Create the HTML files in the view folder /views.


2번 항목에서 app.js 파일을 보면 아래와 같이 기본 템플릿이 Jade 로 설정되어 있는 것을 볼 수 있습니다.



app.set('view engine', 'jade');



이를 지우거나 주석처리를 하고 2번을 진행하시면 됩니다.






+ Recent posts