Created
February 23, 2014 13:54
-
-
Save kanwarujjaval/9171795 to your computer and use it in GitHub Desktop.
Creating multiple forms with a single ejs file in node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="<%= action %>" method="post"> | |
<% if (fields.length) { %> | |
<% fields.forEach(function(field){ %> | |
<label><%= field.name %></label> | |
<input type="<%= field.type %>" name="<%= field.name %>" <% if (field.property) { %> <%= field.property %> <% } %> > | |
<% }) %> | |
<% } %> | |
<button type="submit"><%= title %></button> <!--Title for button is same as that of the page--> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.get('/login', function (req, res) { | |
res.render('form', { | |
title: "Login", //page title | |
action: "/login", //post action for the form | |
fields: [ | |
{name:'email',type:'text',property:'required'}, //first field for the form | |
{name:'password',type:'password',property:'required'} //another field for the form | |
] | |
}); | |
}); |
This is much easier and simpler to implement with EJS than with Angular! Thanks a bunch!
So obvious... it's awesome. EJS for the win!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
WOW - Got here trying to solve the debate between using angular or EJS. Bang!