Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using EJS how do I insert a value if it exists

Tags:

ejs

Why doesn't this work:

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

It throws a reference error saying givenName is not defined, which it may not be and is the reason for the conditional.

like image 479
rob_hicks Avatar asked Oct 23 '22 04:10

rob_hicks


1 Answers

Rob you want to check if (locals.givenName)

 <input type="text" name="givenName" <% if(locals.givenName) {%> value="<%= givenName %>" <% } %>/><br/>
like image 82
Doron Segal Avatar answered Dec 22 '22 23:12

Doron Segal