Search code examples
javascriptjsphtml-emailemail-templates

What language is this, file is javascript. <%= %> and how to do a ternary


I am modifying an email template and from what I have seen it may be JSP expression tags. What I am trying to do is write a ternary for the email template. I get it partially working with,

     <%= data.unitNumber ?  data.unitNumber : " " %>

but what I need done is something along the lines of

<%= data.unitNumber ?  <span>Unit Number: data.unitNumber</span> : " " %>

When I add a tag or a string it no longer works... any help would be appreciated.

Thanks


Solution

  • The language you are using is EJS, see here

    If you are trying to display blocks of HTML i would recommend for a simple if else for simple readibility, because EJS syntax is kind of weird. Here's an example.

    <% if (data.unitNumber) { %>
      <span>Unit Number: <%= data.unitNumber %></span>
    <% } else { %>
        <span> User doesnt exist.  </span>
    <% }  %>
    

    If you want to go for a ternary, check the Ilya Bursov comment 👍