value="<%= giv...">

Using EJS, how do I insert a value if it exists

Why it doesn't work:

 <input type="text" name="givenName" <% if(givenName) {%> value="<%= givenName %>" <% } %>/><br/>


It throws a reference error indicating that givenName is undefined, which may or may not be, and is the reason for the conditional.


source to share

1 answer

You want to check if (locals.givenName)

 <input type="text" name="givenName" <% if(locals.givenName) {%> value="<%= givenName %>" <% } %>/><br/>




All Articles