Thursday, November 15, 2012

expressjs with ... no layout ?!

Yesterday, I was working on a backoffice web application I will be releasing soon for one of my iOS projects. This web application is powered by node.js. I love node.js.
When it comes to creating web apps with nodejs I first had tried to managed all the routing aspects and stuff myself but lately I crossed expressjs.
expressjs is not as overbloated as most web frameworks in my opinion. I like simple stuff because when it comes to debug or extend the thing it's always easier. And it happened, I had to get my hands into expressjs because it appears that the layout abilities were removed from expressjs since 3.0.

The solution they (the developers) give is to have two separate files which you will include in any view before and after your custom content. Something like (with ejs engine):

<%- include 'top.ejs' %>
my custom content
<%- include 'bottom.ejs' %>

As a former ruby on rails developer, I am used to partials and layouts, so this workaround is rather repelling to me.