reading-notes

View on GitHub
Read No. Name of chapter
11 EJS

EJS template engine

Introduction

EJS is among the most popular tempate view engines for node.js and expressjs. EJS simply stands for Embedded JavaScript templates, and we can use it both server-side or client-side. At this story.

Basic Syntax(Tags):

image

Partials

In this section we’ll learn how to use <%- include(‘’)-%> tag.

Project structure:

image

Lets see our index.js file:

image

home.ejs

image

EJS uses <%- include(‘’)-%> tag to include HTML from other files, in our app, we have the HTML templates at /views/template folder.

Render Links

Paste the new router at app.js file with some data to send

image

Create a new file with name links.ejs in views/pages folder and paste the following code

image

This time at res.render function after the name of the file we want to render we pass a JSON object.

image

image