Let’s create a custom function

We create the complementary structure file named dict/01-function.yml so that the my_variable_jinja variable is calculated:

%YAML 1.2
---
version: 1.1

my_variable_jinja:
  default:
    type: jinja
    jinja: "{{ return_no() }}"
...

Then let’s define the return_no() function in functions.py:

the functions.py content
def return_no():
    return 'no'

Then, let’s create the Tiramisu objects via the following script:

the script.py file content
from rougail import Rougail, RougailConfig

RougailConfig['main_structural_directories'] = ['dict']
RougailConfig['extra_namespaces']['example'] = ['extras/']
RougailConfig['functions_file'] = 'functions.py'
rougail = Rougail()
config = rougail.get_config()
print(config.value.dict())

Let’s execute script.py:

$ python3 script.py
{'rougail.my_variable': 'my_value', 'rougail.my_variable_jinja': 'no', 'example.my_variable_extra': 'my_value_extra'}

The value of the my_variable_extra variable is calculated, and it’s value comes from the return_no() function.