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
html_theme
=alabaster
current_version
=0.10.2
version_slug
=0.10.2
MEDIA_URL
=https://media.readthedocs.org/
STATIC_URL
=https://assets.readthedocs.org/static/
PRODUCTION_DOMAIN
=readthedocs.org
proxied_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
=sphinxcontribdatatemplates
name
=sphinxcontrib.datatemplates
rtd_language
=en
programming_language
=py
canonical_url
=None
analytics_code
=None
single_version
=False
conf_py_path
=/doc/source/
api_host
=https://readthedocs.org
github_user
=sphinx-contrib
proxied_api_host
=/_
github_repo
=datatemplates
github_version
=0.10.2
display_github
=True
bitbucket_user
=None
bitbucket_repo
=None
bitbucket_version
=0.10.2
display_bitbucket
=False
gitlab_user
=None
gitlab_repo
=None
gitlab_version
=0.10.2
display_gitlab
=False
READTHEDOCS
=True
using_theme
=False
new_theme
=False
source_suffix
=.rst
ad_free
=False
docsearch_disabled
=False
global_analytics_code
=UA-17997319-1
commit
=38ede3b8