Skip to content

Advanced template

The data you pass in is available in the it variable.

To output data, use the <%= opening tag.

Hi <%= it.name %>

By default, the template will automatically XML-escape the data you output. To allow raw HTML, use the <%~ opening tag.

Hi <%~ it.contentContainingHTML %>

To evaluate JavaScript, use the <% opening tag.

<% let myVar = 3 %>

Comments are just like regular JavaScript multiline comments!

<% /* this is a comment */ %>
## Conditionals
```eta
<% if (it.someval === "someothervalue") { %>
Display this!
<% } else { %>
They're not equal
<% } %>

Note: a “delimiter” means the opening or closing tag.

Opening delimiters can be followed with - or _, and closing delimiters can be prefixed with - or _

_ at the beginning of a tag will trim all whitespace before it, and _ at the end of a tag will trim all whitespace after it.

- at the beginning of a tag will trim 1 newline before it, and - at the end of a tag will trim 1 newline after it.

Hi
<%- = it.myname %>
<% /* %The newline after "Hi" will be stripped */ %>
<% users.forEach(function(user){ %>
<%= user.first %> <%= user.last %>
<% }) %>
<% Object.keys(someObject).forEach(function(prop) { %>
<%= someObject[prop] %>
<% }) %>
<% console.log("The value of it.num is: " + it.num) %>
<%~ await includeAsync("./path-to-partial") %>

For more information about the templating syntax, check out the Eta documentation.