Logic and syntax of Templates |
Variables All variables and commands can be identified by the \ (backslash) symbol in the beginning and end. In the example below you can see the \CLIENT_NAME\, \CLIENT_STREET1\ and \CLIENT_PHONE1\ variables: To: \CLIENT_NAME\ Address: \CLIENT_STREET1\ Phone: \CLIENT_PHONE1\ When you use this template by clicking on Save or Print in some dialog box, the \CLIENT_NAME\ variable will be replaced by name of currently selected client, \CLIENT_STREET1\ — by the client’s street address and \CLIENT_PHONE1\ — by the client’s phone number. The final output will look something like this: To: XYZ Company Address: Elm Street, 1 Phone: +1 212 898 11 31 NOTE: Numerical values are sometimes are surrounded by an fnum command. This command simply tells the parser to round up the value to the specified number of digits after the decimal point (2 digits in the example below): Job Total: \fnum(dtLinkJobs:TOTAL, 2)\
Data Scan commands Another important part of RTF templates are the 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. How to: 1. Begin by entering the \scan(dtLinkJobs)\ command. This must not necessarily be dtLinkJobs, depending on the template, this can be: ·\scan(dtLinkJobs)\ — in invoice templates, to display the jobs included in the invoice. ·\scan(dtLinkInvoices)\ — in payment templates to display the invoices linked to the payment. ·\scan(dtLinkPayments)\ — in invoice templates to indicate the linked sums. 2. Insert the table header between \scan(dtLinkJobs)\ and \scanentry\. 3. Insert one row of data-columns after \scanentry\. Every variable in table must be preceeded with a 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's 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: The command \scan(dtLinkJobs)\ will make the parser scan (go from the first record to the last one) 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)\ command and \scanentry\ command is the table header. The text between \scanfooter\ and \endscan\ commands will be considered the table footer and will only be displayed once at the end of this table. The text between \scanentry\ and \scanfooter\ commands is the table's "body". It includes the variables from columns which must be listed in the table. In the example above these are: ·\dtLinkJobs:PO\ – Client PO Number. ·\dtLinkJobs:COMPLETED\ – Date of job delivery. ·\dtLinkJobs:JOB_NAME\ – Name of the job. ·\dtLinkJobs:SERVICE\ – Service provided.
Condition checking This allows the template to react to certain varying conditions and produce output suitable to each of the possible conditions. The logic is as follows \IF(condition)\ Reaction \ENDIF\. Example: If Discount 1 is applied, display the discount name, discount value and subtotal. The code is as follows:
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, TO3000 3D+ 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 an empty string with and empty Subtotal in cases when there would not be discount. But with the \IF(DISCOUNT1)\ command, in such cases the above block is skipped in its entirety.
See also: |