Skip to main content

Use a Jinja template with a context to create a file.

Tabset

Run​

Recipe​

run:
on_start:
- jinja:
template:
string: |
{% if Brand is defined %} {{ Brand }} {% endif %} {% if ProductType is defined %} {{ ProductType }}, {% endif %}
context:
Brand: Brand
ProductType: Product Type
output_file: my_template.jinja

Function​

from wrangles.connectors import ckan

template_string = '{% if Brand is defined %} {{ Brand }} {% endif %} {% if ProductType is defined %} {{ ProductType }}, {% endif %}'

df = jinja.run(
template={'string': template_string},
context={'Brand': 'Brand', 'ProductType': 'Product Type'},
output_file='my_template.jinja'
)

Parameters​

ParameterRequiredData TypeNotes
template✓objThe template to apply the values to. Either a file or string.
context✓objA dictionary used to define the output template
output_file✓strFile name/path for the file to be output
ifstrA condition that will determine whether the action runs or not as a whole.

Template Parameters​

ParameterRequiredData TypeNotes
filestrA .jinja file containing the template
stringstrA string which is used as the jinja template