Complete 2024 Web Development Bootcamp

Dr. Angela Yu

Back to EJS Index


EJS Reference

There is quite a bit of useful information on the ejs documentation website. One of these references is for the different "elements", or "tags" that we can use when embedding our Js code into our html environment.

 

ejs tags

First there is the syntax that defines the ejs "tag"

  • <%  %>  "Js Execute" - for running Js Code - the code runs but displays no output
  • <%-  %>  "Renders HTML" - processes any html tags for display - eg. <h1></h1>
  • <%=  %>  "Js Output" - usually for outputting a variable
  • <%#  %>  "EJS Comment Tag" - no execution, no output %>
  • <%%  %%>  "Escape Character for EJS" - Literally Outputs "<% %>" - Could be useful for documentation purposes
  • <%_  %>  ‘Whitespace Slurping’ Scriptlet tag, strips all whitespace before it
  • <%- include("anyFile.ejs") %>  "Insert" another ejs file into the current ejs file
  •  

And then we have the closing tags:

  • %>  Plain ending tag
  • -%>  Trim-mode ('newline slurp') tag, trims following newline
  • _%>  ‘Whitespace Slurping’ ending tag, removes all whitespace after it


Back to Top