Logic and Syntax of Templates

Variables

All variables and commands can be identified by the \ (backslash) symbol at the beginning and end. Variables display data extracted from the Projetex database, and relevant to each particular saved document.

Example:

In the example below you can see the \CLIENT_NAME\, \CLIENT_STREET1\ and \CLIENT_PHONE1\ variables, along with some static text:

To: \CLIENT_NAME\

Address: \CLIENT_STREET1\

Phone: \CLIENT_PHONE1\

When you use this template by clicking Save or Print in some dialog box, the \CLIENT_NAME\ variable will be replaced by the name of the current client, valid to this particular document, \CLIENT_STREET1\ — by the client’s street address and \CLIENT_PHONE1\ — by the client’s phone number. The final output will look like this:

To: XYZ Company

Address: Elm Street, 1

Phone: +1 212 898 11 31

Variables like \INVOICE_CODE\ will display the code of the currently saved invoice, variables like \INVOICE_DATE\ will display the issue date of current invoice, and so on.

 

Note: Numerical values are sometimes surrounded by the fnum command. This command simply tells the parser to round up the value to the specified number of digits after decimal point (2 digits in the example below).

Example:

Job Total: \fnum(dtLinkJobs:TOTAL, 2)\

 

Data Scan commands

Another feature of RTF templates are Data Scan commands. These are used to create tables in which the number of rows is determined by the number of records in the database.

1. Begin by entering the \scan(dtLinkJobs)\ command. This must not necessarily be dtLinkJobs, depending on the template, this can be:

2. Insert the table header between \scan(dtLinkJobs)\ and \scanentry\.

3. Insert one row of data-columns after \scanentry\. Every variable in the table must be preceded with the dtlink command. For instance, if the table begins with \scan(dtLinkJobs)\, each variable must have this link included: \dtLinkJobs:JOB_NAME\, \dtLinkJobs:COMPLETED\, and so on.

4. Insert \endscan\ after data-columns.

Note: Use noeof to hide the table's header and footer if the table body appears to be empty. For instance, if your invoice includes only jobs and no expenses, the header and footer for expenses will not be saved/printed.

Example:

\scan:dtlinkJOBS\

PO No.           Job Name

\scanentry\

\dtlinkJobs:PO\  \dtlinkJobs:JOB_NAME\

\scanfooter\

Jobs Total: \JOBS_TOTAL\

\endscan\

The command \scan(dtLinkJobs)\ will make the parser scan through all selected data in the Jobs table (in this particular case all jobs included in the invoice) and output them to the file or printer.

The text between \scan(dtLinkJobs)\ and \scanentry\ is the table header.

The text between \scanfooter\ and \endscan\ is the table footer and will only be displayed once at the end of this table.

The text between \scanentry\ and \scanfooter\ is the table's "body". It includes variables from columns which must be listed in the table. In the example above these are:

 

Condition checking

This allows the template to react to certain varying conditions and produce an output suitable to each of possible conditions. The logic is the following \IF(condition)\ Reaction \ENDIF\.

Example:

If Discount 1 is applied, display the discount name, discount value and subtotal. The code is as follows:

\IF(DISCOUNT1)\

\DISCOUNT1NAME\: \DISCOUNT1VALUE\

Subtotal: \AFTERDISCOUNT1\\endif\

This will make the template check if discount 1 is applied, and if so — display the data between the \IF(...)\ and \ENDIF\ commands.

DISCOUNT1 is a logical variable, i.e. it can have one of two values: either true or false. In this particular case, Projetex sets DISCOUNT1 to true if the first discount is present and to false, if there is no first discount.

When \IF(DISCOUNT1)\ is encountered in the template, the parser checks the DISCOUNT1 logical value, and if it is true, runs the code below this command, until \endif\ is encountered, which instructs the parser to stop. If DISCOUNT1 is false, everything until the \endif\ command is skipped.

In this particular case, without the \IF(DISCOUNT1)\ command, the parser would output the empty string with and empty Subtotal in cases when there would not be discount. But with the \IF(DISCOUNT1)\ command, the above block is skipped entirely if the condition is false.

 

Arithmetic calculations syntax

Arithmetic can be performed in templates with the following syntax:

\((JOBS_TOTAL+100-10)*10)/2\

The whole expression must be included in backslashes;

All arithmetic operations must be defined by the following symbols + - / *;

The brackets inside backlashes must be positioned by the rules of arithmetic.

 

Logical operations syntax

 

Logical operations: && (and), || (or), ! (not),  can be performed in templates with the following syntax:

 

\IF( (table1:field1>b+1) || (table1:field1=0) )\

............

\ENDIF\

 

For more details on Variables for each document type, see the chapters of "Available Template Variables".

It is recommended to begin with the Common Template Variables topic.

 

 

See also:

Template Basics

Advanced commands and functions