Skip to content

Embedded JavaScript #20

@priyakalamkar555-art

Description

@priyakalamkar555-art

Embedded JavaScript (EJS)

EJS is a Templating Engine for Express.js that lets you render dynamic HTML pages using JavaScript variables.

EJS = HTML + JavaScript

Real Life Analogy

  • EJS = chocolate mold
  • Template HTML = shape
  • Data = filling that changes for each page

One of Best & Simple Use of EJS:

  • HTML alone can't do calculation or show dynamic data:

<h2> 2+2 </h2>
output: 2+2 (plain text)

  • EJS allows JavaScript Logic directly in HTML:

<h2><%= 2+2 %></h2>
output: 4

Simple Structure Program:

Image

app.set('view engine', 'ejs'); // this line tell express to use EJS for rendering pages with dynamic content

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions