Last Updated: February 25, 2016
· kanwarujjaval

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><%= %></label>
        <input type="<%= field.type %>" name="<%= %>" <% if ( { %> <%= %> <% } %> >
    <% }) %>

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