--- id: 5895f700f9fc0f352b528e63 title: Set up a Template Engine challengeType: 2 videoUrl: '' localeTitle: 设置模板引擎 --- ## Description
提醒一下,这个项目是基于Glitch的以下入门项目构建的,或者是从GitHub克隆的。模板引擎使您可以在应用程序中使用静态模板文件(例如用Pug编写的文件)。在运行时,模板引擎将模板文件中的变量替换为可由服务器提供的实际值,并将模板转换为静态HTML文件,然后将其发送到客户端。这种方法可以更轻松地设计HTML页面,并允许在页面上显示变量,而无需从客户端进行API调用。要设置Pug以便在项目中使用,您需要先在package.json中将其作为依赖项添加。 "pug": "^0.1.0"现在告诉Node / Express使用模板引擎,你必须告诉你的快递应用程序 'pug' 设置为'view-engine'。 app.set('view engine', 'pug')最后,你应该改变请求您响应该指数路线res.render与路径视图意见/哈巴狗/ index.pug。如果一切按计划进行,您应该刷新应用程序主页并看到一条小消息,说您已成功从我们的Pug文件中删除Pug!当您认为自己已经做对时,请提交您的页面。
## Instructions
## Tests
```yml tests: - text: 帕格是一个依赖 testString: 'getUserInput => $.get(getUserInput("url")+ "/_api/package.json") .then(data => { var packJson = JSON.parse(data); assert.property(packJson.dependencies, "pug", "Your project should list "pug" as a dependency"); }, xhr => { throw new Error(xhr.statusText); })' - text: 查看引擎是帕格 testString: 'getUserInput => $.get(getUserInput("url")+ "/_api/server.js") .then(data => { assert.match(data, /("|")view engine("|"),( |)("|")pug("|")/gi, "Your project should set Pug as a view engine"); }, xhr => { throw new Error(xhr.statusText); })' - text: 帕格正在工作 testString: 'getUserInput => $.get(getUserInput("url")+ "/") .then(data => { assert.match(data, /pug-success-message/gi, "Your projects home page should now be rendered by pug with the projects .pug file unaltered"); }, xhr => { throw new Error(xhr.statusText); })' ```
## Challenge Seed
## Solution
```js // solution required ```