Context¶
The template context for each markdown file includes:
all key/value pairs in the
markdownfrontmatterrendered
markdownHTML incontentJSON data from the
datadirectorycoltranewhich includes a dictionary of thecoltranesettingsnowwhich provides the currentdatetime(would be the time of HTML rendering for when generating a static site)requestwhich provides the current requestdebugwhich contains theDEBUGsetting (or ifINTERNAL_IPShas the current request’s IP)slugwhich contains the current file’s “slug” (e.g.articles/some-new-articleif there was a markdown file atcontent/articles/some-new-article.md)tocwhich is an automatically generated table of contents rendered as HTMLif
publish_dateis found, it is converted to a Pythondatetimeinstance using the excellent dateparser library
Example context¶
data/index.json
{ "test": "Great" }
content/index.md
---
this_is_a_variable: This is a good test
template: some_app/custom-template.html
publish_date: 2022-02-26 10:26:02
---
{{ this_is_a_variable }}
Data from JSON files: {{ data.index.test }}
Current datetime: {{ now }}
Publish date: {{ publish_date|naturalday }}
some_app/templates/some_app/custom-template.html
{{ content }}
Generated index.html
<p>This is a good test</p>
<p>Data from JSON files: Great</p>
<p>Current datetime: 8 Jan. 11, 2022, 10:02 p.m.</p>
<p>Publish date: Feb. 26, 2022</p>