Doctrine templates essentially allow you to extract schema information
so that it can be plugged in to multiple Doctrine classes without having
to duplicate any code. Below we will show some examples of what a
template could be used for and how it can make your schema easier to
maintain.

Let’s get started. Imagine a project where you have multiple records
which must have address attributes. Their are two basic approaches to
solving this problem. One is to have a single table to store all
addresses and each record will store a foreign key to the address record
it owns. This is the “normalized” way of solving the problem. The
“de-normalized” way would be to store the address attributes with each
record. In this example a template will extract the attributes of an
address and allow you to plug them in to as many Doctrine classes as you
like.

First we must define the template so that we can use it in our Doctrine
classes.