Skip to content

Iterations

Overview

OpenReport allows to declare a loop and add repetitively (a set of) similar objects. The "loop" instance specifies the loop settings and adds the same block of components to the "document" fixed number of times. Loop can be set manually or can be obtained using the "source" instance.

Back to homepage


Manual

This specification declares a loop with iterator "year" using "iterator_name" property. The "iterator_type" property specifies the method the iterator is set: "manual" or "source". With "manual" the iterator is specified manually using "iterator_values" property.

- document:
    name: document.docx
    structure:
      - loop:
          iterator_name: year
          iterator_type: manual
          iterator_values: [2025, 2026]
          iterator_applicable:
            - text:
                body: Total sales for year @iterator{year} have increased.
The "iterator_applicable" instance lists all components to be added to the "document" repeatedly. Current value of iterator is accessible with @iterator{iterator_name} format. With every next iteration the @iterator{year} value will change to the next item of "iterator_values" list.

Iterator usage

The specification above declares iterator (year) with manually specified values [2025, 2026], therefore the document will contain:

Total sales for year 2025 have increased.
Total sales for year 2026 have increased.
Nested loops are supported.

Back to homepage


Source

With "source" the iterator values are an output of "source" instance. For example:

- text:
    body: "The sales per month are:"
- loop:
    iterator_name: sales_month_i
    iterator_type: source
    source:
      output: array
      source_type: python
      python_executable: calculate_sales_per_month 
    iterator_applicable:
      - text: 
          body: " - @iterator{sale_month_i} EUR" 
This specification declares a loop with iterator "sales_month_i" using "iterator_name" property. The "iterator_type" property specifies the method the parameter is set: "manual" or "source". With "source" the values of the iterator are an output of user-defined function 'calculate_sales_per_month'.

Iterator usage

The specification above declares iterator (sales_month_i). If the script outputs [10, 20, 30], the document will contain:

The sales per month are:
 - 10 EUR
 - 20 EUR
 - 30 EUR
Nested loops are supported.

Back to homepage


Required properties

Required properties for "loop" instance is "iterator_name", "iterator_type", "iterator_applicable" and depending on "iterator_type" value either "iterator_values":

- loop:
    iterator_name: 
    iterator_type: manual
    iterator_applicable:
      # ...
    iterator_values:

Or "source":

- loop:
    iterator_name: 
    iterator_type: source
    iterator_applicable:
      # ...
    source:
      # ...

Continue to Document iterations

Back to top

Back to homepage