Anatomy of a Template II - Headers and Filler
By Tim Dexter on Mar 28, 2007
Continuing on from yesterday, today we'll add in the repeating header and a filler for the invoice lines. Imagine you have pre-printed stationary, yesterday we tacled how to get X number of lines on each page, now assume that on the last page of the document you need a summary at the bottom of the page. If that last page only has 5 rows of data and we were printing 20 rows on the previous pages then once the 5 rows are rendered the summary will then render directly under the five rows i.e. not at the bottom of the last page ... still with me? With 5.6.2 we introduced the concept of a last page only command; we could use that here but I want to continue with the idea of filler rows and we'll tackle the last page only option later.
Taking a batch invoices as our example we can add the header and the filler rows.
Reset your Head
For the header we want to have say an invoice header with page numbering, etc. As we hit a new invoice we want the header information to change and the page numbering to reset. To do this we can use the '@section' option for the for-each command. We create the header layout in the MSWord header.
Notice we can not put formfields in to the MSWord header section so we either need to type in the commands or use a header template and reference it.
The only extra fields added are:a
FE G_INVOICE - this starts the looping over each invoice using the @section to reset the header information as each new invoice is reached.
EFE - this closes out the loop above
Running this template (Inv_Header.rtf) gives us two invoices with a repeating header on each page with page numbering per invoice.
Now lets add the logic for the filler rows, you can see the new fields and empty table just below the lines table in the Inv_Header_Spacer.rtf template. There are two new fields
Filling Out Space - this contains the logic to check if the number of rows rendered above equals the lines per page variable. If not then insert the table row until it does.
<?if:not(count($invLines) mod $lpp=0) and ($start+$lpp>count($invLines))?>
<?if:position()<$lpp - (count($invLines) mod $lpp)?>
then we have the blank table row, then
End Filling - this just closes out the for-each and the if statements.
I just added a static string 'End of padded lines' to check that we are actually padding. Complete samples available here.
Next, page totals and last page only ...