Skip to content

anisul-Islam/ejs-documentation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

My Embedded Javascript (ejs) Documentation

Total Chapters are following

  1. Introduction ejs
  2. Passing data
  3. if else
  4. loop
  5. layout
  6. styling
  7. deploy on heroku

What is ejs & Why ejs?

  • ejs stands for embedded javascript

  • ejs is a templating language.

  • templating language helps us to manipulate dynamic content in HTML document.

  • Templating language: ejs, handlebars, pug etc.

  • Ejs allows us to run plain js in HTML

  • Ejs simple, light weight, fast

  • Most downloaded templating language on npm

  • Founded in Feb, 2011

  • how to use ejs

      // first install ejs:
      npm install ejs
    
      // inside the server
      app.set('view engine', 'ejs');
    
      // create index.ejs inside views folder
      res.render('index',{});
  • create and pass the data

  • syntax: <%= variable %>

    let pLanguages = ["c", "c++"];
    
    app.get("/", (req, res) => {
      res.render("index", { plNames: pLanguages });
    });
    
    //inside the index.ejs
     <li><%= plNames[0] %></li>
  • if, else syntax:

      <% if () { %>
          // do whatever
       <% } else { %>
          // do whatever
       <% } %>
    <% if(plNames){ %>
    <li><%= plNames[x] %></li>
    <% }else{ %>
    <p>no data found</p>
    <% } %>
  • loop control statement

  • syntax:

      <% for () { %>
          // do whatever
       <% } %>
    <% for(let x=0; x<plNames.length; x++){ %>
      <li><%= plNames[x] %></li>
      <% } %></plNames.length;
    >
  • create layout and use it anywhere
  • To use a layout syntax : <%- include("layout/header") %>

About

In this repository I will share my knowledge related to ejs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published