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. 【扩展欧几里得】codevs1200-同余方程

    [题目大意] 求关于 x 同余方程 ax ≡ 1 (mod b)的最小正整数解. [思路] 求解ax+by=1,只要x<0就不断加上 b. #include<iostream> #i ...

  2. Lua脚本

    应用场景: 游戏开发 独立应用脚本 Web 应用脚本 扩展和数据库插件如:MySQL Proxy 和 MySQL WorkBench 安全系统,如入侵检测系统 1. 在很多时候,我们可以将Lua直接嵌 ...

  3. git零基础【慢慢补充】

    git branch dev   //创建新分支 git checkout dev   //切换到新分支 git add .  //把当前修改加到暂存区 git commit -m "代码描 ...

  4. opencv第二课 进行缩放图片~

    #include<stdio.h> #include<iostream> #include<opencv2\opencv.hpp> using namespace ...

  5. webpack vuejs 和 vue-router 如何使用?

    读本文之前,建议对webpack和vuejs有初步的了解,通过webpack的官网和vuejs的中文官网了解即可 网站主要目录://某些文件不一定全部罗列出来,注意观察 vue-wepack -src ...

  6. cocos2dx 3.0 中文 iconv 转换函数

    //#include <string> #pragma once #include "cocos2d.h"; #include "iconv\include\ ...

  7. 如何编写LVS对Real Server的健康状态检测脚本

    简介:Linux 虚拟服务器(Linux Virtual Server. LVS),是一个由章文松开发的自由软件.利用KVS可以实现高可用的.可伸缩缩的Web, Mail, Cache和Medial等 ...

  8. Tasker to proximity screen off

    If you are using proximity screen off pro or smart screen off, you may know how convenient it is to ...

  9. 模拟登陆CSDN——就是这么简单

    工具介绍 本篇文章主要是解说怎样模拟登陆CSDN.使用的工具是HttpClient+Jsoup 当中HttpClient主要是负责发送请求,而Jsoup主要是解析HTML 你可能对HttpClient ...

  10. 用Parallel.For()和Parallel.For<TLocal>()方法实现并行运行迭代

    Parallel类是.NET 4中新增的抽象线程类.如果你开发用的是VS2008或更低版本,那么就直接关闭吧,下面两个示例用了匿名委托,如果不知道匿名委托的语法,那么先去简单了解一下,不然很难理解示例 ...