Skip to main content

OneDoc Tagging Syntax

OneDoc templates are processed by referring them to a data source. Tagging in the template refers to elements of the data source to control execution and derive values to be printed in the document.

Execution of the template walks the structure and sets the cursor, represented by a period '.' and called ‘dot’ to the value at the current location in the structure as execution proceeds.

Tag Structure

All OneDoc tags will start with two opening square brackets [[ followed by a STATEMENT and end with two closing square brackets ]].

The STATEMENT can be an ACCESSOR  or a VARIABLE or a METHOD.

Accessor

An accessor is a reference in a data source from the current location.

For example, if your data source provider is a SOQL query (select name from contact) and the reference field is defined as ‘contact’ then the accessor will be [[.contact.name]] to print the value of the name field from the contact object.

Variable

OneDoc tagging allows you to use a variable within a template design. Just like any other programming, a variable has to be declared initially and used later.

The custom variables need to be prefixed with $ sign.

Syntax to declare a variable [[$variableName := initializer]]. An initializer can be an empty string or the datasource. For example, to declare a variable ‘contactName’ is written as [[$contactName := “”]]

To declare and assign a value to a variable $contactName is written as [[$contactName := .contact.name]]. To reassign a new value to the declared variable is written as [[$contactName = .contact.name]]. Only during initialization of a variable colon equal := is used after that just like any other programming to reassign a new value only equal = to be used.

Method

OneDoc supports the following methods to be used in the following format.

            [[name arguments]]

All methods can be chained using pipe. For example, to add 2 numbers and minus a number.

[[add 5 3 | minus 10]]. The result of the first method will be passed as a final argument in the chain of the next method. So, the result will be 10 - 8 which is 2.

  1. and method returns the boolean AND of its arguments by returning the first empty argument or the last argument,
    • for example “[[and x y]]” means if x and y are true then the result is true. If one of the values is false, then it returns false.

  2. or method returns the boolean OR of its arguments by returning the first empty argument or the last argument,
    • for example “[[or x y]]” means if x or y are true then the result is true. If one of the values is true, then it returns true.

  3. len returns the integer length of its argument.
    • for example [[$x := “Hi”]] “[[len $x]]” returns 2.

  4. not returns the boolean negation of its single argument. 
    • For example [[not x]]

  5. index returns the result of indexing its first argument by the following arguments.
    • Thus “index x 1 2 3” is read as x[1] [2] [3]. For example [[index x 1 2 3]]

  6. add method to add arguments. add supports more than 2 arguments.
    • For example to add $first and $second variables  [[add $first $second]].

  7. minus method to minus only 2 arguments. minus do not support more than 2 arguments.
    • For example to minus $first and $second variables  [[minus $first $second]].

  8. mul method to multiply 2 numbers -  [[mul $first $second]]
  9. div method to divide 2 numbers -  [[div $first $second]]
  10. cfloat method to convert to float -  [[cfloat $first]]
  11. format method to format a number for example $unitPrice to 2 precision - [[format “%.2f” $unitPrice]]
  12. removeml method to remove any markup tags from the data.
    • For example [[removeml "<b>Hi</b>"]] will print Hi

  13. print method to concatenate string - [[print "Hello" " " "World."]] will display in the output document as Hello World.
  14. image method to print an image - [[image $url $width? $height? $position?]]
  15. wmtext method to print a text watermark in the document – [[wmtext string]]
  16. rtf method to print a rich text format – [[rtf string]]
  17. qrcode method to print a QR code - [[qrcode, $string $width? $height? $position?]]

Date and Time methods

OneDoc doesn’t use yyyy-mm-dd layout to format a date and time. Instead, you format a special layout parameter

Mon Jan 2 15:04:05 MST 2006

the same way as the time or date should be formatted. (This date is easier to remember when written as 01/02 03:04:05PM ‘06 -0700.)

  1. datef to format a date - [[datef $opportunity.createdDate “2006-01-02” “01-02-2006”]] In the above example, createdDate field is in the format of ‘2006-01-02’ and printing in format of ‘01-02-2006’. Please remember to use only “2006-01-02” for formatting syntax.
  2. idatef to format an international date format for example $opportunity.createdDate  [[idatef $opportunity.createdDate “01-02-2006”]]. In this example,
Date and Time Layout options

Type

Options

Year

06   2006

Month  01  

1   Jan   January

Day

02   2   _2   (width two, right justified)

Weekday

Mon Monday

Hours

03 3 15

Minutes

04 4

Seconds

05 5

ms μs ns

.000   .000000   .000000000

ms μs ns

.999   .999999   .999999999   (trailing zeros removed)

am/pm

PM pm

Timezone

MST

Offset

-0700   -07   -07:00   Z0700   Z07:00


Boolean Functions

The Boolean functions take any zero value to be false and a non-zero value to be true. There is also a set of binary comparison operators defined as functions:

  1. eq - Returns the boolean true of arg1 == arg2

    Example [[if eq $arg1 $arg2]] Hi [[end]]

    The above condition prints Hi if  arg1 equals to arg2

  2. ne - Returns the boolean true of arg1 != arg2

    Example [[if ne $arg1 $arg2]] Hi [[end]]

    The above condition prints Hi if  arg1 not equal to arg2

  3. lt - Returns the boolean true of arg1 < arg2

    Example [[if lt $arg1 $arg2]] Hi [[end]]

    The above condition prints Hi if  arg1 less than arg2

  4. le - Returns the boolean true of arg1 <= arg2

    Example [[if le $arg1 $arg2]] Hi [[end]]

    The above condition prints Hi if  arg1 less than or equal to arg2

  5. gt - Returns the boolean true of arg1 > arg2 

    Example [[if gt $arg1 $arg2]] Hi [[end]]

    The above condition prints Hi if  arg1 greater than arg2

  6. ge - Returns the boolean true of arg1 >= arg2

    Example [[if ge $arg1 $arg2]] Hi [[end]]

    The above condition prints Hi if  arg1 greater than or equal to arg2
  7. contains - Returns the boolean true when any of the arg is matched

    Example [[if contains $arg1 $arg2 $arg3]] Hi [[end]]

    The above condition prints Hi if  arg1 contains arg2 or arg3 etc.
Logical Functions
  1. If statement
    [[if statement]] T1 [[end]]
    If the value of the statement is empty, no output is generated; otherwise, T1 is printed. The empty values are false, 0, any nil pointer or interface value, and any array, or string of length zero.
  2. [[if statement]] T1
    [[else]] T0
    [[end]]
    If the value of the statement is empty, T0 is printed; otherwise, T1 is printed.
  3. [[if statement]] T1
    [[else if statement]] T0
    [[end]]
    To simply the appearance of if-else chains, the else action of an if may include another if directly; the effect is exactly the same as writing
  4. [[if statement]] T1
    [[else]]
    [[if statement]] T0
    [[end]]
    [[end]]

Note: Any nested statements within an If statement to start in a new line. For example [[else]], [[else if statement]], etc within an If statement should start in a new line within a document.


Table Statement (loop statement)

[[tableStart ($k, $v as statement) ]]
T1
[[tableEnd]]

The value of the statement must be an array or map. If the value of the statement has length zero, nothing is output; otherwise, execution is set to the successive elements of the array or map and T1 is printed.

If the value is a map and the keys are of basic type with a defined order, the elements will be visited in sorted key order.

Template comments

OneDoc supports commenting within a template. [[/* to open and */]] to close a comment block. Nothing within that block will be rendered in the output document. Comments do not nest and must start and end at the delimiters.

For example: Bonsoir, [[/* add 0 + 2 */]] Eliott. Will render Bonsoir, Eliott., and not care about the ‘add 0 + 2’ in the comment block.