[Node.js]26. Level 5 : Route rendering
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的更多相关文章
- [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 ...
- [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 ...
- [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 ...
- [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 ...
- [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 ...
- [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 ...
- [Node.js]22. Level 4: Dependency
Add two dependencies to your package.json file, connect and underscore. You'll want to useconnect ve ...
- [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 ...
- [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 ...
随机推荐
- 火狐FoxyProxy配置教程
原文:http://www.lvtao.net/tool/640.html 虽然autoproxy是火狐上最优秀的代理插件,但是好久不更新,也有一些bug,比如观看youtube视频7分钟左右会无法播 ...
- Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分
D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...
- ASP.NET 构建高性能网站 第1篇
网站优化需要考虑的方面 在用ASP.NET开发网站的时候,性能是永远需要考虑和关注的问题,性能不仅仅只是程序代码执行时候的速度,而是涉及到方方面面的东西. 就拿ASP.NET的一个请求来讲,从浏览器向 ...
- TPS70345 (ACTIVE) 双路输出低压降 (LDO) 稳压器
The TPS703xx family of devices is designed to provide a complete power management solution for TI DS ...
- 修改WampServer的默认端口
WampServer默认的安装端口是80,容易和已安装的ISS等其他服务冲突,导致WampServer无法启动. 无法启动的现象如下: 1.apache服务无法启动.问题所在:80端口冲突. 2.在浏 ...
- Maven学习-使用Nexus搭建Maven私服
为什么要搭建nexus私服,原因很简单,有些公司都不提供外网给项目组人员,因此就不能使用maven访问远程的仓库地址,所以很有必要在局域网里找一台有外网权限的机器,搭建nexus私服,然后开发人员连到 ...
- 在 CentOS 和 RHEL 上安装 Puppet 服务器和客户端
https://linux.cn/article-3959-1.html https://docs.puppet.com/
- blurImage做图片模糊处理报错free(): invalid next size
$image = new Imagick($url); $image->blurImage($x, $y); 调用blurImage($x, $y)函数报错: 原因是:原来的图片是CMYK的是印 ...
- .Net高级技术——对象序列化
对象序列化 “序列化是将一个对象保存到存储介质上或者将对象进行转换使之能够在网络上传送的行为”.通俗一点的解释,序列化就是把一个对象保存到一个文件或数据库字段中去,反序列化就是从文件或者数据库中取出数 ...
- [Apache] Apache 從 2.2 換至 2.4 httpd.conf 的調整筆記 (windows 環境)
原文地址: http://www.dotblogs.com.tw/maplenote/archive/2012/07/20/apache24_httpd_conf.aspx 整理一下 Windows ...