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.pyhtml_theme=alabastercurrent_version=latestversion_slug=latestMEDIA_URL=https://media.readthedocs.org/STATIC_URL=https://assets.readthedocs.org/static/PRODUCTION_DOMAIN=readthedocs.orgproxied_static_path=/_/static/versions=[('latest', '/en/latest/'), ('stable', '/en/stable/'), ('0.10.2', '/en/0.10.2/'), ('0.10.1', '/en/0.10.1/'), ('0.10.0', '/en/0.10.0/'), ('0.9.2', '/en/0.9.2/'), ('0.9.1', '/en/0.9.1/'), ('0.9.0', '/en/0.9.0/'), ('0.8.1', '/en/0.8.1/'), ('0.8.0', '/en/0.8.0/'), ('0.7.2', '/en/0.7.2/'), ('0.7.1.post1', '/en/0.7.1.post1/'), ('0.7.1', '/en/0.7.1/'), ('0.7.0', '/en/0.7.0/'), ('0.6.1', '/en/0.6.1/'), ('0.6.0', '/en/0.6.0/'), ('0.5.0', '/en/0.5.0/'), ('0.4.0', '/en/0.4.0/'), ('0.3.0', '/en/0.3.0/'), ('0.2.0', '/en/0.2.0/'), ('0.1.0', '/en/0.1.0/')]downloads=[]subprojects=[]slug=sphinxcontribdatatemplatesname=sphinxcontrib.datatemplatesrtd_language=enprogramming_language=pycanonical_url=Noneanalytics_code=Nonesingle_version=Falseconf_py_path=/doc/source/api_host=https://readthedocs.orggithub_user=sphinx-contribproxied_api_host=/_github_repo=datatemplatesgithub_version=masterdisplay_github=Truebitbucket_user=Nonebitbucket_repo=Nonebitbucket_version=masterdisplay_bitbucket=Falsegitlab_user=Nonegitlab_repo=Nonegitlab_version=masterdisplay_gitlab=FalseREADTHEDOCS=Trueusing_theme=Falsenew_theme=Falsesource_suffix=.rstad_free=Falsedocsearch_disabled=Falseglobal_analytics_code=UA-17997319-1commit=a8852381