O'Reilly logo

HTML5 Data and Services Cookbook by Mite Mitreski, Gorgi Kosev

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required