1) A template is always designed against a result set (a query). A result set can return one or multiple rows (or none).
When the result set contains multiiple row (like the invoice rows in the demo / documentation), you often need initialization for the result set (for example for invoice row HTML table headers), you need to show the actual data (invoice rows) and at the end, you need to close the table tags. In a template, you would define the headers in the template header section, put the actual row HTML in the rows section, and then close the table in the template footer section.
When the result set contains just one row, a template is a simple one-to-one mapping where result set variables will be placed in the template code. In case of just one row returned, you do not need any header or footer sections as you can do all necessary in the row-section.
You can place also additional HTML to header/footer sections (CSS styles, JavaScript code etc) as these are placed in the reports only once.
The invoice template example uses three separate templates, one for the header (logo, dates, invoice nbr), one for the rows, and one for the rows footer (implemented as separate template as the data for it comes from separate query).
2) You can define the template in myDBR templates section, in case you would refer to the template by its name "#invoice_header". This is the most common use of templates.
The other alternative which you can use (usually if the template is very simple), is to define the template HTML directly in the dbr.template-command ('row template code' would be the equivalent of the templates row-section.
Take a look at the documentation to see the full code and explanation for the invoice-template example.
--
myDBR Team