-
Book Overview & Buying
-
Table Of Contents
HTML5 Data and Services Cookbook
One of the most common tasks when using a template language is to render a list of items. Since EJS is based on escaping to JavaScript, rendering lists can be done using the loop constructs in the language.
In this recipe, we're going to render a list of message objects. Each message object will have an author, arrival time, body, and read status. We're going to use a different style to distinguish between read and unread messages.
We need to download EJS from http://embeddedjs.com/ and extract ejs_production.js in our recipe folder.
Let's get started.
Create index.html, it will contain a header, the EJS template, the placeholder to render the message list, and some styles for the list:
<!DOCTYPE HTML>
<html>
<head>
<title>Rendering an array with EJS</title>
<style type="text/css">
.message {
border-bottom:solid 1px #ccc;
width: 250px;
padding: 5px; }
.message p { margin: 0.5em 0; }
.message...
Change the font size
Change margin width
Change background colour