Template syntax | Commands

<< Click to display table of contents >>

Template syntax | Commands

See the topic about fields in templates for a general description of the syntax.

All commands are case insensitive.

The current version of Report Workshop supports commands only inside a template text. They are not supported in strings (such as data queries, hyperlink targets, item hints and checkpoints).

"HEADER" and "FOOTER"

These commands define a part of document to apply the document's data query.

This data query is applied to the part of document between {$HEADER} and {$FOOTER}

These commands are special:

they are valid only if the document's data query is defined

they must start a new paragraph

the next item (if exists) must start a new paragraph as well

all text on the same line as {$HEADER} and {$FOOTER} is discared

these commands are processed before any other commands, so they cannot be placed inside "If" command.

Example:

Fruits:

{$HEADER}

- {FruitName}

{$FOOTER}

Generated {=CurDate()}

produces a result like this:

Fruits:

- Apples

- Oranges

- Pears

Generated 21.12.2021

Do not rely to the order of processing headers and footers (it may be important if you use "Set" commands to assign variable values).

Currently, the order is the following:

if the document's data query returns 0 records, a header is processed before a footer;

otherwise, the order of processing: a repeated part, a footer, a header.

But this order may be changed in future.

"IF – ENDIF" or "IF – ELSE – ENDIF"

"If" command allows excluding some content from the report result. It may be optionally followed by "Else" command, and must be finished by "EndIf" command.

All these commands must be in the same sub-document (i.e. in the same table cell)

Syntax:

<if> ::= if <if condition>

<if condition> ::= <expression text>

See the topic about expressions on definition of <expression text>.

Example 1:

Two identical examples:

{$IF count}Count of details: {count}{$ELSE}No details available{$ENDIF}

{$IF count<>0}Count of details: {count}{$ELSE}No details available{$ENDIF}

 

{$IF test="Passed"}OK{$ENDIF}

 

{$IF weight>200}Too heavy{$ENDIF}

This command can also be used in scripts.

"IFDEF – ENDIF" or "IFDEF – ELSE – ENDIF"

"IfDef" command is similar to "If", it has a similar syntax and meaning, but a condition is evaluated differently.

Syntax:

<ifdef> ::= ifdef <condition>

<condition> ::= <full data field name>|%<variable name>|#<cross-tab field>

Example:

{$IFDEF phone2}Phone 2: {phone2}{$ENDIF}

<value> may be either a data field or a variable.

A data field in the condition must exist, otherwise the command is erroneous. NULL fields (or empty string fields) are evaluated as False, any other values are evaluated as True.

For variables, non-existent or empty variables are evaluated as False, variables having non-empty text are evaluated as True.

"IFNDEF – ENDIF" or "IFNDEF – ELSE – ENDIF"

"IfNDef" command is similar to "IfDef", but the rule of condition evaluating is exactly the opposite.

Syntax:

<ifndef> ::= ifndef <condition>

<condition> ::= <full data field name>|%<variable name>|#<cross-tab field>

Example:

{$IFnDEF comments}No comments{$ENDIF}

"LISTRESET"

"ListReset" specifies when the paragraph numbering must be reset to 1. This command must be inserted in a numbered paragraph, otherwise it is erroneous.

Syntax:

<listreset> ::= listreset[ <depth>]

<depth> is an integer value, zero or positive. If omitted, zero is assumed.

By default, paragraph numbering is continuous through the whole document. This command allows to reset it to 1.

The depth parameter specifies the data query on which the list is reset. 0 means the most nested query, 1 means the query containing it, and so on.

Example:

Let we need to generate an organization structure. There are queries "bosses", "managers", "workers", having a master-detail relationship.

Without ListReset

{$LISTRESET 1}

{$LISTRESET} or {$LISTRESET 0}

boss A
  manager A
    1. worker A
    2. worker B
  manager B
    3. worker C
    4. worker D
boss B
  manager C
    5. worker E
    6. worker F
  manager D
    7. worker G
    8. worker H

boss A
  manager A
    1. worker A
    2. worker B
  manager B
    3. worker C
    4. worker D
boss B
  manager C
    1. worker E
    2. worker F
  manager D
    3. worker G
    4. worker H

boss A
  manager A
    1. worker A
    2. worker B
  manager B
    1. worker C
    2. worker D
boss B
  manager C
    1. worker E
    2. worker F
  manager D
    1. worker G
    2. worker H

"SET"

Assigns the variable value.

Syntax:

<set> := set [']%<variable name>['] to <expression text> | set [']%<variable name>['] = <expression text>

See the descriptions of variables and expressions.

These two versions of SET command are almost identical, but there is a difference in handling undefined variables. The version with "TO" reports an error for unknown variables. The version with "=" adds a new variable in global Variables.

This command can also be used in scripts (and it's recommended to use scripts for variables assignments).

Example:

{$set %hello = "Hello world"}{%hello}

produces

Hello world

Example:

Please note that values of variables are strings, so

{$set %v to 1}{$set %v to %v+1}{%v}

produces

11

because the variable value becomes "11".

To produce 2, convert the variable to a number:

{$set %v to 1}{$set %v to ToNumber(%v)+1}{%v}

or

{$set %v to 1}{$set %v to +%v+1}{%v}