Express template engines
Express template engines
Typically in a project environment you need to know multiple template engines because every engine has got its own strength and weaknesses. Mainly we will discuss on EJS template engine.
To build node.js web apps its important to understand how to use templates. We will see how to use
Why you should know multiple template engines?
As already mentioned that different template engines has different featured being offered, so for their convenient purpose people use them. And this brings you the fact that in real world you are most likely to work on different projects that use different template engines, so it becomes very important that you know how to work with different templates.
In any node.js application that we are writing to create a web server say your web based app is going to have 10 pages so you will be having 10 different paths to your application url.
... so on.
And with different url user generally go to different pages and page navigation happens within the application itself. So far we are trying to create HTML page on the server side but it is very well possible that within your code itself you can write your HTML tags within “ ”.
So this is one very crude way of sending a HTML to the end users. And this is where templates engine come in play and what they do is they provide a very nice way for creating HTML pages. In a typical HTML page that is seen on your browser you have static tags in which data is spread everywhere like some data you will find in tabular form which are written in <table> tag. So basically there are some structural elements of HTML and within that HTML page itself you have your data spread in some or other component of HTML page.
We can use the application generator tool to quickly create an application skeleton. We can use
express-generator package which will let us easily generate the infrastructure for new projects. Since we are at the beginning of learning so we will not use application generator tools.
So right now I’m not going to tell about code generator now, though its a very small and easy thing to learn but once the code gets generated then you won’t be able to understand what to change, why to change and things like that. So that’s why we will be generating our code manually and once you become proficient with the template engines then we will generated the code and then make changes to the generated code to suite our needs.
A bit about bootstrap