:title: Variables
:date: 2022-09-22
=========
Variables
=========
The following variables are passed to the template. Đ•ach variable corresponds
to a data source, which is described in the previous article.
``page``: dict
Dictonary with article attributes. Data structure example:
.. code-block:: python
page = {
'title': 'Variables',
'date': '2022-09-22',
}
Note that the ``type`` and ``template`` keys are missing. These keys are
added implicitly. The ``page`` dict will always contain only the data
specified directly in the article.
Here ``type`` and ``template`` fallbacks to defaults:
.. code-block:: text
'template': `template.jinja2`
'type': 'page',
Usage example:
.. code-block:: jinja
{{ page.title }}
``site``: dict
Dict of values from ``site`` section from **settings.toml**. The structure
and data types can be arbitrary.
This data can be used to add custom elements common to the entire site.
Below is an example of adding a list of links.
.. code-block:: toml
[site]
title = 'My awesome site'
description = 'Awesome site about awesome things'
[[site.links]]
title = 'GitHub'
url = 'https://github.com/username'
[[site.links]]
title = 'Twitter'
url = 'https://twitter.com/username'
This data is serialized into a dictionary with the following structure:
.. code-block:: python
site = {
'title': 'My awesome site',
'description': 'Awesome site about awesome things',
'links': [
{
'title': 'GitHub',
'url': 'https://github.com/username',
},
{
'title': 'Twitter',
'url': 'https://twitter.com/username',
}
]
}
In template:
.. code-block:: jinja
{% for link in site.links %}
{{ link.title }}
{% endfor %}
``aggr``: dict
This dictonary contains list of posts and list of pages. The elements of
each list consist of dictionaries with strings.
Structure of the ``aggr`` dictonary:
.. code-block:: python
aggr = {
'posts': [
{
'title': 'Hello, World!',
'date': '1970-01-01',
'type': 'post'
},
{
'title': 'reStructuredText Example',
'date': '1970-01-01',
'type': 'post'
}
],
'pages': [
{
'title': 'Variables',
'date': '2022-09-22'
}
]
}
These lists are applicable, for example, to display a list of posts on the
blog's main page.
``pygments_theme``: str
A string containing the name of the Pygments theme. In **settings.toml**:
.. code-block:: toml
[pygments]
theme = 'rrt'
The default theme is ``default``. An example of usage in a template:
.. code-block:: jinja