4.5. Creating templates the easy way

Once you learn the basic notions of building a template, all you have to do is create a document with the right layout.

The previous section introduced the template language using plain text files. However plain text files are just plain. They are easier to understand and create but you can't have fancy layouts with headers, footers, page numbering and the like. One easy way to do this is to use a visual editor like Adobe Dreamweaver, Microsoft Word or LibreOffice Writer.

This section shows how to use placeholders, built-ins and directives with HTML, Microsoft Word or OpenDocument Text documents. Before you read any further, please make sure you read the first section as it tells how to use directives in tables.

4.5.1. Using directives in tables (important!)

If you read the section on directives, you probably noticed that directives start and end on separate lines. Since HTML, Microsoft Word or OpenDocument Text documents allow other elements than just paragraphs of text, this translates differently if you use tables.

Let's use a table to represent the services, products and expenses of an invoice:

Table 4.37. Invoice items in a table

Name Quantity Price Total
Services      
Service1 5 $10 $50
Service2 2 $5 $10
       
Products      
Product1 1 $10 $10
       
Expenses      
Expense1 1 $30 $30
       
Total     $100

The template that produces this table looks as follows. Please observe that the start and end of a directive are emphasized and placed on separate lines. You can also color these lines in gray to distinguish them easier. They will be removed by Fanurio when it processes the template.

Table 4.38. Template code for invoice items in a table

Name Quantity Price Total
Services      
[#list invoice.serviceItems as item]      
${item.name} ${item.quantity} ${item.price} ${item.total}
[/#list]      
       
[#if invoice.productItems?size != 0]      
Products      
[#list invoice.productItems as item]      
${item.name} ${item.quantity} ${item.price} ${item.total}
[/#list]      
[/#if]      
       
[#if invoice.expenseItems?size != 0]      
Expenses      
[#list invoice.expenseItems as item]      
${item.name} ${item.quantity} ${item.price} ${item.total}
[/#list]      
[/#if]      
       
Total     ${invoice.total}

4.5.2. HyperText Markup Language (.html)

An HTML template is similar to the plain text template created in the previous section but with specific formatting like header, footer, page numbering and a table for the invoice items.

HTML is a very popular file format that's used especially for web pages. It's also the default file format for templates used in Fanurio. Fanurio can use templates in several file formats but only HTML templates can be used for both viewing and exporting invoices to PDF. A comparison of all file formats is available at the end of this guide.

One easy way to create an HTML template is to use the template editor. Another way (although not recommended) is create it by hand. If you prefer to create it manually, you may want to use a visual editor like Adobe Dreamweaver (commercial) or KompoZer (free).

We also have a separate section that shows how to fine-tune an HTML document.

4.5.3. Microsoft Word (.docx)

A Microsoft Word 2007 template is similar to the plain text template created in the previous section but with specific formatting like header, footer, page numbering and a table for the invoice items.

Please note that Fanurio can only handle Microsoft Word 2007 (.docx) files. Older Microsoft Word formats are not supported. Templates created for Microsoft Word are regular files for which you have to disable a few settings.

Disable random numbers, grammar and spell check

Although this is something you don't see as a user, Word adds various details to a document that prevent Fanurio from using it as a template. To fix this problem, you need to disable a few settings.

To Remove RSID (not available in the Mac version)

  1. Click the Microsoft Office Button, and then click Word Options

  2. Click Trust Center, and then click Trust Center Settings

  3. Click on Privacy Options

  4. Uncheck "Store random number to improve combine accuracy"

To Remove Grammar and Spell check

  1. Click the Microsoft Office Button, and then click Word Options

  2. Click Proofing

  3. Click to clear the Check spelling as you type check box.

  4. Click to clear the Mark grammar as you type check box.

When adding Freemarker code to a Microsoft Word template, you may want to cut the text and paste it back as unformatted text. This ensures that the text is inserted as a block and it's not split in multiple invisible fragments.

4.5.4. OpenDocument Text (.odt)

An OpenDocument Text template is similar to the plain text template created in the previous section but with specific formatting like header, footer, page numbering and a table for the invoice items.

When adding Freemarker code to a OpenDocument Text template, you may want to cut the text and paste it back as unformatted text. This ensures that the text is inserted as a block and it's not split in multiple invisible fragments.

4.5.5. OpenDocument Spreadsheet (.ods)

An OpenDocument Spreadsheet template is similar to the plain text template created in the previous section.

When adding Freemarker code to a OpenDocument Spreadsheet template, you may want to cut the text and paste it back as unformatted text. This ensures that the text is inserted as a block and it's not split in multiple invisible fragments.