Advanced template
Basic Syntax
Section titled “Basic Syntax”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<% } %>
Whitespace Control
Section titled “Whitespace Control”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 */ %>
Looping over arrays
Section titled “Looping over arrays”<% users.forEach(function(user){ %> <%= user.first %> <%= user.last %><% }) %>
Looping over objects
Section titled “Looping over objects”<% Object.keys(someObject).forEach(function(prop) { %> <%= someObject[prop] %><% }) %>
Logging to the console
Section titled “Logging to the console”<% console.log("The value of it.num is: " + it.num) %>
Async Partials
Section titled “Async Partials”<%~ await includeAsync("./path-to-partial") %>
For more information about the templating syntax, check out the Eta documentation.