EJS syntax

Here's a short guide to EJS syntax. For more information, consult the official EJS documentation.

NOTE

When using EJS templating engine, all variables are available under one top-level variable named it. For example, to access context variable listed in the table below, you must write it.context.

Variables

You refer to variables like this:

1<%= it.variable_name %>

If the variable is an object with properties of its own, you can refer to them like so:

1<%= it.person.firstName %>

Comments

You can use EJS comments in your files. Commented out sections won't show up in the final rendered output.

1<%# This comment will not show up in the output %>

If-conditions

Here's an example of if-condition:

1<% if (it.some_variable) { %>
2  this will be included in the output
3<% } %>

Iterating over collections

This is how you iterate over a collection of items:

1<% it.securityGroupIds.forEach(function(sg){ %>
2<%= sg %>
3<% }) %>

Escaping expressions

If you don't want to process a EJS expression, you can escape it like so:

1<%% this content is not processed %>