Macro Evaluate Function#

  • fn.evaluate: Evaluate the string using the macro interpreter.

    The string can be a macro and can also contain macro names to be evaluated.

    The purpose of the function is so that we can save data as a macro and then evaluate it when we read it again.

    For example, we may store default values in a data model (e.g. SiteDefaultsDoc) that may also refer to existing macros. An attribute of the model - with name: defaulthppt can for example have the value (The macro evaluates to a site name):

    Site-{{macro.SITENAME}}
    

    Then, a workflow Configuration Template at a Site can be a set to a value that references the model and that uses fn.evaluate:

    "defaulthppt": "{{ fn.evaluate data.SiteDefaultsDoc.defaulthppt }}",
    

    Not:

    "defaulthppt": "Site-{{macro.SITENAME}}",
    

The tables below provide further examples.

Where self.x specifies an attribute of a model, with the value:

{# data.Countries.iso_country_code | country_name:'South Africa' #}

Example

Output

Then:

{# fn.evaluate self.x #}
['ZAF']

Where MACRO1 is:

{{ data.Countries.emergency_access_prefix | iso_country_code:FRA }}

Where self.x is:

{# data.Countries.iso_country_code | emergency_access_prefix:macro.MACRO1 #}

Example

Output

Then:

{# fn.evaluate self.x #}

Codes with same prefix as FRA:

['DNK','HKG',
 'FRA','DEU',
 'IND','ITA',
 'NLD','NZL',
 'SAU','ESP',
 'SWE','ZAF',
 'CHE','TUR']