- Node.js 6.x Blueprints
- Fernando Monteiro
- 207字
- 2021-07-14 10:35:04
Refactoring the views folder
As we did before, let's change the views
folder to the following new structure:
views
pages/
partials/
- Remove the default
jade
files formviews
folder. - Create a file called
layout.html
inside thepages
folder and place the following code:<!DOCTYPE html> <html> <head> </head> <body> {% block content %} {% endblock %} </body> </html>
- Create an
index.html
inside theviews/pages
folder and place the following code:{% extends 'layout.html' %} {% block title %}{% endblock %} {% block content %} <h1>{{ title }}</h1> Welcome to {{ title }} {% endblock %}
- Create an
error.html
page inside theviews/pages
folder and place the following code:{% extends 'layout.html' %} {% block title %}{% endblock %} {% block content %} <div class="container"> <h1>{{ message }}</h1> <h2>{{ error.status }}</h2> <pre>{{ error.stack }}</pre> </div> {% endblock %}
- We need to adjust the
views
path onapp.js
, and replace the code right aftervar app = express();
function with the following code:// view engine setup app.set('views', path.join(__dirname, 'views/pages'));
At this time we have completed the first step of starting our MVC application. In the previous chapter we used pretty much of the original structure created by the express command, but in this example we will use the MVC pattern in its full meaning, Model, View, Controller.
推薦閱讀
- Vue.js前端開發基礎與項目實戰
- Three.js開發指南:基于WebGL和HTML5在網頁上渲染3D圖形和動畫(原書第3版)
- Scratch 3.0少兒編程與邏輯思維訓練
- Spring實戰(第5版)
- Visual Basic程序設計實驗指導(第4版)
- C++ 從入門到項目實踐(超值版)
- Expert Data Visualization
- 利用Python進行數據分析(原書第3版)
- MATLAB for Machine Learning
- Django 3.0入門與實踐
- C# Multithreaded and Parallel Programming
- Node.js 12實戰
- Emotional Intelligence for IT Professionals
- Raspberry Pi Blueprints
- 第五空間戰略:大國間的網絡博弈