博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Node.js]26. Level 5 : Route rendering
阅读量:6196 次
发布时间:2019-06-21

本文共 1162 字,大约阅读时间需要 3 分钟。

Instead of just writing out the quote to the response, instead render the quote.ejs template, passing in the quote name and quote body.

Then finish the quote.ejs view, by printing out the quote name and body.

var express = require('express');var app = express.createServer();var quotes = {  'einstein': 'Life is like riding a bicycle. To keep your balance you must keep moving',  'berners-lee': 'The Web does not just connect machines, it connects people',  'crockford': 'The good thing about reinventing the wheel is that you can get a round one',  'hofstadter': 'Which statement seems more true: (1) I have a brain. (2) I am a brain.'};app.get('/quotes/:name', function(request, response) {  var quote = quotes[request.params.name];    // render template here  response.render('quote.ejs', {name:request.params.name, quote: quote});});app.listen(8080);

quote.ejs

Quote by <%= name%>

<%= quote%>

 

Oops, we forgot to include a layout file.

We've started one below. Finish it out by including the body of the template inside of the <body> tag. Remember to use the <%- tag so the template contents are not escaped.

      Quotes        <%-body%>  

 

转载地址:http://odjca.baihongyu.com/

你可能感兴趣的文章
C#播报语音:检索 COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046} 的组件时失败...
查看>>
操作数据库(数据操作类)
查看>>
C#窗体
查看>>
数据库 基础知识篇(二)sql语句概述
查看>>
MyBatis的逆向工程、Example类
查看>>
hdu 1007 Quoit Design (Nearest Point Pair)
查看>>
LightOJ 1203 Guarding Bananas (Convex Hull)
查看>>
Linux0.11---A20地址线
查看>>
面向对象
查看>>
iOS线程开发总结
查看>>
blender2.7.4安装three.js插件
查看>>
要素缩放闪烁功能
查看>>
Selenium简单回顾
查看>>
获得时间
查看>>
IIS连接数
查看>>
.Net Framework
查看>>
633E Binary Table
查看>>
C++ 顺序容器(vector,list、deque,stack,queue)
查看>>
【LeetCode每天一题】Flatten Binary Tree to Linked List(二叉树转化为单链表)
查看>>
关于路由跟踪指令---traceroute
查看>>