Last Updated: February 25, 2016
·
3.111K
· 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><%= 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

https://gist.github.com/kanwarujjaval/9171795