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

<h2>Quote by <%=  name%></h2>

<blockquote>
<%= quote%>
</blockquote>

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.

<!DOCTYPE html>
<html>
<head>
<title>Quotes</title>
</head>
<body>
<%-body%>
</body>
</html>

[Node.js]26. Level 5 : Route rendering的更多相关文章

  1. [Node.js]25. Level 5. Route params

    Create a route that responds to a GET request '/quotes/<name>', then use the param from the UR ...

  2. [Node.js]24. Level 5: Express, Express routes

    Create an express route that responds to GET requests at the URL /tweets that responds with the file ...

  3. [Node.js]31. Level 7: Redis coming for Node.js, Simple Redis Commands

    Let's start practicing using the redis key-value store from our node application. First require the  ...

  4. [Node.js]30. Level 6: Listen 'Question' from client, and then Answer the Question

    Clients can also answer each other questions, so let's build that feature by first listening for the ...

  5. [Node.js]29. Level 6: Socket.io: Setting up Socket.io server-side & Client socket.io setup

    Below we've already created an express server, but we want to start building a real-time Q&A mod ...

  6. [Node.js]23. Level 4: Semantic versioning

    Update the versions on your dependencies to be a little more flexible, adding the ~ in front of your ...

  7. [Node.js]22. Level 4: Dependency

    Add two dependencies to your package.json file, connect and underscore. You'll want to useconnect ve ...

  8. [Node.js]33. Level 7: Persisting Questions

    Let's go back to our live-moderation app and add some persistence, first to the questions people ask ...

  9. [Node.js]32. Level 7: Working with Lists -- Redis

    As we saw in the video, redis can do more than just simple key-value pairs. We are going to be using ...

随机推荐

  1. 洛谷.4512.[模板]多项式除法(NTT)

    题目链接 多项式除法 & 取模 很神奇,记录一下. 只是主要部分,更详细的和其它内容看这吧. 给定一个\(n\)次多项式\(A(x)\)和\(m\)次多项式\(D(x)\),求\(deg(Q) ...

  2. BZOJ 1528 [POI2005]sam-Toy Cars(优先队列)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1528 [题目大意] 地上最多可以放k个玩具,现在给出需求顺序, 问最少需要去架子上拿几 ...

  3. java设计模式(六)策略模式

    适用于同一操作的不同行为,策略模式定义了一系列的算法,并将每一个算法封装起来,而且使它们可以相互替换,让算法独立于使用它的客户而独立变化,具体应用场景如第三方支付对接不同银行的算法. 要点:1)抽象策 ...

  4. JVM垃圾回收(GC)流程

    /* 首先介绍一下JVM中堆内存的组成: JVM堆内存主要由三部分组成: (1)新生代: 伊甸园区,存活区,伸缩区 (2)老年代: 老年区,伸缩区 (3)元空间(永久代): 元空间,伸缩区 注意:JD ...

  5. Reverse Engineering the NC ECU (revisited) -- SH7508

    http://forum.miata.net/vb/showthread.php?t=536601 Hey all! About 5 years ago, there was a great thre ...

  6. 邮件基本常识普及(to/cc/bcc)

    http://blog.sina.com.cn/s/blog_5572b4b5010009ul.html 前两天,某个同事发的一封邮件着实把我给郁闷了,他发的是图片形式的笑话,内容稍稍有点不太健康,这 ...

  7. Oracle中NVARCHAR2与VARCHAR2的相互转换

    将NVARCHAR2转换为VARCHAR2: declare v_username   varchar2(12)   ; v_nm_login   nvarchar2(12); begin selec ...

  8. 淘宝海量数据库之八-攻克随机IO难关 -----阿里正祥的博客

    http://blog.sina.com.cn/s/blog_3fc85e260100qwv8.html

  9. WCF服务端调用client.

    wcf服务端 1,新建一个"windows窗口程序"名称为WCFServer2. 2.然后加入一个"WCF服务"名称为Service1. 详细步骤为:解决方式试 ...

  10. 常用NFS mount选项介绍

    通过NFS挂接远程主机的文件系统时,使用一些不同的选现可以使得mount比较简单易用.这些选项可以在mount命令中使用,也可以在/etc/fstab和autofs中设定.  以下是NFS mount ...