Example Templates and rules for template creation



Most important to know:

All 'tags' are enclosed in double brackets. Like [[this]].

A tag should only contain letters, numbers and the _ (underscore) sign.

If a tag does not show up in the form, it is very likely somehow (invisibly) broken in the document.
Remove the entire tag and write it down again. Do not correct misspelled tags. Remove them completely and add them again.


Also important to know: basic formating rules

There is normal substitution:
Just place a tag like [[firstname]] inside your document. This will generate an input field for your form called 'firstname'.
View a minimalistic example.

Lists:
You can fill tables with lists.
The software needs a way to identify that a table row is meant to be replicated and filled with data.
For that, there are 'list_keys'. Whenever template2pdf sees a list_key inside a table, it assumes that the table-row where the list-key is found, is meant to be replicated.
Take an invoice as example. You might would want a list of items. Each of this items should have an id, a title and a price.
You could write [[list_key_item]] to identify a row,
and you would call your item values: [[item_id]], [[item_title]] and [[item_price]]
Take a look at this example, to see the usage of one table with the list key 'item'.
Take a look at this example, to see the usage of two table with different list keys.

Images:
For each image that you want to insert into your document, you will need a placeholder image that will get substituted.
Just insert this placeholder image into your document. Then right click on it, select 'Picture' got the the 'Option'-tab and change the name into a tag.
For example: [[my_logo_IMAGE]].
Your next tag could be called [[other_picture_IMAGE]]
If you are inside a table-row that you want to replicate, call the image something like: [[item_brandlogo_IMAGE]]
Take a look at the following example to see how easy it is.
Attention: Do not try to re-use the same placeholder by copying it inside the document. You need to insert individual files as placeholders.

Calculations inside spreadsheets:
If you want to do calculations inside spreadsheets, you need to make sure the software knows to put in numbers instead of text into your table-cell.
Append _FLOAT to your tag and the cell will get formated to contain numeric values.
So instead of writing [[worked_hours]] you would write [[worked_hours_FLOAT]] into the table-cell.
Take a look at this example for the usage of _FLOAT.

A small trick to fix formulas:
Imagine a invoice table, containing the items and the price per item.
To get the total amount, you would write something like that:
=SUM(<C2:C5>)       - (sum up all values from C2 to C5)
At the time you write your template, you have no knowledge about how many items you will enter in the future.
Sadly, self referencing formulas are only working for imported spreadsheets, but not for normal writer tables.
If you can live with an imported spreadsheet, you can use a self referencing formula like this one:
=SUM(C2:INDIRECT(CONCATENATE("C",(ROW()-1))))

If you prefer the less powerful, but nicer native tables, you can make template2pdf fix the formula on the fly:
=SUM(<C2:?>)FIX_CELL_SUM_item       - would count how many times the list-key 'item' got inserted and fix the formula accordingly.
For 4 inserts, the formula would change into:
=SUM(<C2:C5>)      
See this example for a demo of both kind of formulas.