jinjaΒΆ
Creates one or multiple files based on a given Jinja template in source
.
data
must be a dictionary and its keys can be used as identifier in the template.
Example for single data element
template file
Path: templates/say_hello.rst.template
Hey Hooo!
It's {{name}} from {{city}}!
conf.py file
collections = [
'jinja_test': {
'driver': 'jinja',
'source': 'templates/say_hello.rst.template',
'target': 'my_jinja_test.rst',
'data': {
'name': 'Max',
'city': 'Munich'
},
'active': True,
},
]
The values inside {{..}}
get replaced by the related value from the data dictionary.
If multiple_files
is set to True
, data
must be a list and the driver gets executed
for each element (dict) in this list.
To get also a new file for each element of the list, you can use Jinja syntax also in target
and
source
.
Example for multiple data element
template file
Path: templates/say_hello.rst.template
Hey Hooo!
It's {{name}} from {{city}}!
conf.py file
collections = [
'jinja_test': {
'driver': 'jinja',
'source': 'templates/say_hello.rst.template',
'target': 'my_jinja_test_for_{{name|lower}}.rst',
'data': [
{
'name': 'Max',
'city': 'Munich'
},
{
'name': 'Sandra',
'city': 'Barcelone'
},
],
'active': True,
},
]
This example would create two files: my_jinja_test_for_max.rst
and my_jinja_test_for_sandra.rst