Template provides a way to create templates using the HTML fragments. It contains HTML elements and various placeholders which are replaced with the values of the fields present in the data that is given to the template API to use in conjunction with the template text. For example, we may have a <div>
element present in the body and, based on the data, we may add
<ul>
and <li>
elements to it at runtime.
In this recipe, we will look at a typical usage of template and understand what it takes to define and use one.
Make sure that you have set up your development environment by following the Gear up for the Journey recipe outlined in Chapter 1.
Create a new folder named ch04
in the same folder where we created the ch01
and ch02
folders. We will be using this new folder in which to keep the code.