Inline Sample¶
This example demonstrates how to use an inline template, as well as
accessing the HTML context available to all
datatemplate directives, regardless of the data format.
Data File¶
{
"key1": "value1",
"key2": [
"list item 1",
"list item 2",
"list item 3"
],
"nested-list": [
["a", "b", "c"],
["A", "B", "C"]
],
"mapping-series": [
{"cola": "a", "colb": "b", "colc": "c"},
{"cola": "A", "colb": "B", "colc": "C"}
]
}
HTML Context¶
# from conf.py
html_context = {
'sample': 'Sample context value set in conf.py',
}
An Inline Template¶
.. datatemplate:json::
:source: sample.json
Individual Item
~~~~~~~~~~~~~~~
{{ data['key1'] }}
List of Items
~~~~~~~~~~~~~
{% for item in data['key2'] %}
- {{item}}
{% endfor %}
HTML Context
~~~~~~~~~~~~
{% for key, value in config.html_context.items() %}
- ``{{key}}`` = ``{{value}}``
{% endfor %}
Rendered Output¶
Individual Item¶
value1
List of Items¶
list item 1
list item 2
list item 3
HTML Context¶
sample=Sample context value set in conf.py