Using template engines with Express

Posted stefzi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Using template engines with Express相关的知识,希望对你有一定的参考价值。

  • 安装模板引擎
$ npm install pug --save
  • 设置模板路径
app.set(‘views‘, ‘./views‘)
  • 设置模板引擎
app.set(‘view engine‘, ‘pug‘)
  •  创建模板页面
//Create a Pug template file named index.pug in the views directory, with the following content:
html
  head
    title= title
  body
    h1= message
  • 渲染模板页面
const express = require(‘express‘)

let app = express()

app.set(‘views‘, ‘./views‘)

app.set(‘view engine‘, ‘pug‘)

app.get(‘/‘, function (req, res) 
    res.render(‘index‘, title: ‘Hey‘, message: ‘Hello there!‘)
)

app.listen(80)

 

以上是关于Using template engines with Express的主要内容,如果未能解决你的问题,请参考以下文章

Data liberation pattern using the Debezium engine

Data liberation pattern using the Debezium engine

Using 3D engines with Qt(可以整合到Qt里,不影响)

mysql执行 sql文件遇到USING BTREE ) ENGINE=MyISAM DEFAULT CHARSET=utf8错误

kubernetes installing and using

[Angular 2] Using ng-for to repeat template elements