- 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.
推薦閱讀
- 軟件項目管理(第2版)
- Java高并發(fā)核心編程(卷2):多線程、鎖、JMM、JUC、高并發(fā)設計模式
- Responsive Web Design with HTML5 and CSS3
- The React Workshop
- OpenStack Cloud Computing Cookbook(Fourth Edition)
- Julia機器學習核心編程:人人可用的高性能科學計算
- Oracle數(shù)據(jù)庫從入門到運維實戰(zhàn)
- INSTANT CakePHP Starter
- Visual C++應用開發(fā)
- The Complete Coding Interview Guide in Java
- 區(qū)塊鏈技術與應用
- Unity 2017 Game AI Programming(Third Edition)
- 創(chuàng)意UI Photoshop玩轉移動UI設計
- Magento 2 Beginners Guide
- Elasticsearch搜索引擎構建入門與實戰(zhàn)