Playing With EJS

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 254:- Playing With EJS

EJS (Embedded JavaScript) is a simple templating language that lets you generate HTML markup with plain JavaScript. It's easy to use and provides a lot of features to make it flexible and powerful.

Here are some basic examples of how to use EJS:

  1. Outputting Variables:

    In EJS, you can output the value of a variable by placing it inside <% %> tags. For example, to output the value of a variable named "title", you can use the following code:

    htmlCopy code

    <h1><%= title %></h1>

  2. Conditional Statements:

    You can use conditional statements in EJS to generate different content based on certain conditions. For example, to generate content only if a variable "isLoggedIn" is true, you can use the following code:

    htmlCopy code

    <% if(isLoggedIn) { %>  <p>Welcome back!</p> <% } %>

  3. Looping over Arrays:

    You can loop over arrays in EJS using the <% %> tags and the JavaScript forEach() method. For example, to generate a list of items from an array named "items", you can use the following code:

    htmlCopy code

    <ul>  <% items.forEach(function(item) { %>    <li><%= item %></li>  <% }); %> </ul>

  4. Including Partials:

    EJS allows you to include partial templates using the <% include %> tag. For example, to include a header and a footer partial in your template, you can use the following code:

    htmlCopy code

    <% include header %> <h1><%= title %></h1> <% include footer %>

These are just a few examples of what you can do with EJS. With its simple syntax and powerful features, it's a great choice for generating dynamic HTML content in Node.js applications.

29. My First Express App - A List Of Contacts!

2 Comments

@niteshguptav63
niteshguptav63 Nov 17, 2024 at 1:39 PM

I am not able to access videos from second class and further. I have already completed first class

@niteshguptav63
niteshguptav63 Nov 16, 2024 at 10:56 AM

When will I get my course?

@admin79
admin79 Nov 17, 2024 at 1:29 PM

Now, Your query was resolved.

Frequently Asked Questions About Sciaku Courses & Services

Quick answers to common questions about our courses, quizzes, and learning platform

Didn't find what you're looking for?

help_center Contact Support