Create multiple forms using ejs and express in Node.js
A simple piece of code to create multiple forms with a single ejs file and render different html forms with express and node.js.
<% fields.forEach(function(field){ %>
<label><%= field.name %></label>
<input type="<%= field.type %>" name="<%= field.name %>" <% if (field.property) { %> <%= field.property %> <% } %> >
<% }) %>
This ejs script iterates through every field passed to the ejs rendered page and renders page by giving field name, type and additional property.
The fields are passed through array of objects. find the complete code in the following gist
Written by Kanwar Ujjaval Singh
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Express
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#