The office document template is a LibreOffice document written normally, except for the significant fact ;-) that it will contain computer code, allowing to display data from the context, to have conditions, to run loops, to incorporate sub-templates, etc.
When generating the document in a given context, the computer code present in the template is "interpreted" and replaced by data to produce the final document.
The computer syntax used is that of the appy framework library, whose "pod" module manages the generation of the document. The "gen" module of that library is not used.
It is possible to insert the computer code in several ways, all explained below. The presence of this computer code does not prevent formatting.
The easiest way to edit a template saved in Plone is to use the "external editor" feature to edit the document and, after each save, directly test the build.
The first way to perform the data merge (inserting context data into the document) is to use an input field. To insert a field, in LibreOffice, you must position your cursor at the desired place and go through the "Insert" menu, then "Field" and finally "More fields ..." (or CTRL + F2).
The following window appears:
Insert -> Field -> More Fields
After selecting the "Functions" tab and the "Input field" type, click (once) on "Insert". An additional window is displayed, allowing to enter the computer code in the field.
You must type the statement in the second field: in this example "context.title" which will retrieve the "title" attribute of the context. After clicking "OK", the field is inserted into the document. Then, close the "Fields" window to return to the document (by clicking on the "Close" button, or the "x" button, or with the "Esc" key).
To edit an input field, click on it once, which places the mouse cursor at the end of the statement.
This field has a purpose identical to the input field but adds a notion of condition. If the condition is true at the time of document generation, the field is rendered. If the condition is false, the field is not rendered and is left in the document, for the purpose of being rendered later! This is the case, for example, of a mail merge field that must be rendered only after the mail merge action.
To insert a Conditional Text field, in LibreOffice, you must position your cursor in the desired position and go through the "Insert" menu, then "Field" and finally "More fields ..." (or Ctrl + F2).
After having selected the "Functions" tab and the "Conditional Text" type, fill in the fields:
- "Condition": this is the condition that will be tested to see if the field should be rendered or not.
- "Then": this is the instruction of the field. Beware: these two fields must be defined as text, i.e. surrounded by single or double quote.
Finally, click (only once) on "Insert" to insert this field. It is then necessary to close the "Fields" window to return to the document (by clicking "Close", or "x" or with the "Esc" key).
AT first glance, the Conditional Text field looks like the Input field, but if you hover the mouse cursor on it for 2 seconds, the condition appears on a black background.
It is also possible to more easily distinguish the 2 types of fields via the following method. Via the "View" menu, click on "Field Names" or use the shortcut "Ctrl + F9".
The input field does not display any particular information while the Conditional Text field contains the type as well as the condition in addition to the field code.
To modify a conditional text field, double click it. This will open a window almost identical to the insertion which allows to modify the values.
A comment allows to introduce code to carry out more complex operations than to integrate a simple value in the document. It will allow the following things:
- integrate document parts via sub templates.
- evaluate conditions for the rendering of a section, paragraph, title, table, table row, or table cell.
- run loops to repeat the rendering of the same types of elements mentioned above.
- define variables to simplify the computer code.
To insert a comment in LibreOffice you must position your cursor at the desired place and use the "Insert" menu, then "Comment" (or Ctrl + Alt + c).
The comment is displayed in the right column and it allows you to enter the desired code.
In our example, the code renders the corresponding paragraph if the toto variable is set.
To edit a comment, simply position the cursor inside it.
When generating from this template on the context of the homepage of a standard site and with the variable "toto", we obtain the following result:
With the same template but without the variable "toto", we obtain the result:
We can see that the paragraph related to the comment is missing and that the Conditional Text field has not been rendered.