Rendering objects using EJS

EJS is a template language that allows users to mix HTML and JavaScript inside the template. Similar to PHP and ERB, it works by adding extra tags to HTML which allow the user to "escape" from HTML to the programming language and use the full facilities of that language.

In this recipe, we're going to demonstrate EJS using a simple example. We're going to render a user greeting based on the time of the day.

Getting ready

We need to download EJS from http://embeddedjs.com/ and extract ejs_production.js in our recipe folder.

How to do it...

Let's get started.

  1. Create index.html containing a name input, a greeting placeholder, and an EJS template:
    <!DOCTYPE HTML> <html> <head> <title>Displaying an EJS object</title> </head> <body> ...

Get HTML5 Data and Services Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.