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!

Comments: 2

profile
@niteshguptav63
17-Nov-2024, 01:39 PM

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

profile
@niteshguptav63
16-Nov-2024, 10:56 AM

When will I get my course?

profile
@admin79
17-Nov-2024, 01:29 PM

Now, Your query was resolved.

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?