Operations in DOCX templates

Operations can be applied to the data source property that contains an array of objects. It allows processing the data before putting them into the template.

List of operations

filter

The operation returns an array of the objects that meet a condition and assign them to a token initiated with alias.

Syntax:

{{filteredObjects = objects|filter(value.objectProperty != false)}}

Available operators:

  • == equal to,

  • != not equal to,

  • > more than,

  • < less than,

  • >= more than or equal to,

  • <= less than or equal to,

  • || logical “or”,

  • && logical “and”,

  • () group.

Example

Template

Data

Result

{{filteredColors = colors|filter(value.name != “green”)}}

Filtered colors:

  • {{filteredColors.name}}

{
  "colors": [
    {
      "name": "red"
    },
    {
      "name": "green"
    },
    {
      "name": "blue"
    }
  ]
}

Filtered colors:

  • red

  • blue

top

The operation returns a specified number of the top objects from the array and assign them to a token initiated with alias.

Syntax:

{{topObjects = objects|top(3)}}

Example

Template

Data

Result

{{topColors = colors|top(2)}}

Top colors:

  • {{topColors.name}}

{
  "colors": [
    {
      "name": "red"
    },
    {
      "name": "green"
    },
    {
      "name": "blue"
    }
  ]
}

Top colors:

  • red

  • green

at

The operation returns a certain object from the array by its index and assign it to a token initiated with alias.

Syntax:

{{atObject = objects|at(2)}}

Example

Template

Data

Result

{{atColor = colors|at(1)}}

My favorite color is {{atColor.name}}.

{
  "colors": [
    {
      "name": "red"
    },
    {
      "name": "green"
    },
    {
      "name": "blue"
    }
  ]
}

My favorite color is green.