Lesson 278 – Complete 2020 Web Development Bootcamp

Lesson 278 – Running Code Inside the EJS Template

Scriplet tags can be used in your .ejs file to allow you to run code within your .ejs file.

A scriplet tag is written like this –

<%  %>

Scriplet tags are used for flow control – not output. So scriplet tags can be used on if/else statements, switch statements, etc.

This is an example of a list.ejs file with an else/if statement in scriplet tags –

<!DOCTYPE html>
<html>
<head>
	<title>To Do List</title>
</head>
<body>

	<% if (kindOfDay === "Saturday" || kindOfDay === "Sunday") { %>

	<h1 style="color: purple"><%= kindOfDay %> ToDo List</h1>

<% } else { %>
	
	<h1 style="color: blue"><%= kindOfDay %> ToDo List</h1>

<% } %>

</body>
</html>