O1 Templates
O1 is a template processor written in GoLang and developed by OBS. This temaplate processor can be used only as part of the OBS ERP package. It has the following text processing features:
- variables
- functions
- text replacement
- loops
- conditional evaluation
1. Show all available variables
~.show_vars.~
Result (invoice number):
VAR |
VALUE |
amount |
8700.00 |
contract_id |
2015-09-23 №28 Test Customer |
... |
.... |
2. Display value of variable: Enclosing sequence:
~~variable~~
Example:
~~invoice_id~~
Result (invoice number):
14
3. Translate keyword as per the definitions in the "Translations" module:
Enclosing sequence
~_variable_~
Example:
~_qty_~
Result:
Quantity
4. Create a table with values
4.1 Table with automatic layout:
Enclosing sequence:
~#table_name^table #~
Example:
~#invoice_items^table;#~
Result:
# |
name |
qty |
price |
1 |
Test |
1 |
100 |
You can skip a column by adding the skip keyword as shown below:
~#invoice_items^table; skip:photo; #~ ( this will skip the photo column )
4.2. Table with custom columns
Enclosing tag:
~#table_name^table; ~column_one~ ~column_two~ ~column_three~ #~
Example:
~#invoice_items^table; ~SEQ~ ~name~ ~qty~ ~price_per_unit~ ~discount~ ~line_total~#~
* ~SEQ~ will create a column with sequential numbers, starting from 1.
Result:
# |
name |
Quantity |
Price per unit |
Discount |
Total |
1 |
Test |
1 |
100 |
1 |
99 |
4.2.1 Functions
The data in a column can be passed to a function. For example:
To show an image inside the table use showImageInTD function:
~#quotation_items^table; ~SEQ~ ~.showImageInTD^~product_image~,products,3.5.~ ~price_per_unit~ #~
Alternatively, you can use any data processing function in the table.
4.3. Table with custom header.
This section describes how to create tables with custom header like the one below:
4.3.1. Create a new template holding the custom table header. The name of the template will be used later. For example:
# |
Date |
Principle |
Monthly installments |
Taxes and commissions |
Remaining Principle |
Interest |
Principle |
Amount |
4.3.2. Generate the table using the following syntax:
~#invoice_items^table_with_custom_header:thead_template;~name~ ~qty~ ~price_per_unit~ ~discount~ ~line_total~#~
Where:
* table_with_custom_header - the name of the layout
* thead_template - the name of the template created as described in point 1
* ~name~ ~qty~ ~price_per_unit~ ~discount~ ~line_total~ - the names of the columns. Can be omitted.
5. Display value in case it exists:
Enclosing sequence:
~?variable; ?~
~?variable; displayed if set ^ displayed if not set ?~
Example:
~?description; This is a description: ~~description~~ ?~
In case it does not exist:
~?description; This is a description: ^ Text displayed in case description is not set ~~description~~ ?~
6. Display variable containing HTML code:
Function: open_template
Example:
{{ open_template (index $.MainRecord "comment") }}
7. Functions
~.function_name^param1,param2,......~
Example:
~.translate^bottle.~
8. Import template
You can import a template into another template using the following syntax:
~.import^template_name.~
Where "template_name" is the name of the template you would like to import
9. Custom logic: You can use the HUGO templating langugage to implement custom logic in your templates
Last modified: 13.08.2017