Context variables
The Mako templates, whether they are stand-alone or being used to render markdown (or other) content, receive the following context variables:
DATADIR
: The full path to thedata
directory.WEBROOT
: The full path to thehtdocs
directory.CONTENTDIR
: The full path to thecontent
directory.TEMPLATES
: A list of all templates which will potentially be rendered as stand-alone. Each item in the list contains the keyssrc
(relative path to the source template),src_path
(full path to the source template),target
(full path of the file to be written), andurl
(relative url to the file to be written).MDCONTENT
: AnMDContentList
representing all the content files which will potentially be rendered by a template. Each item in the list contains the keyssource_file
,source_file_short
(truncated and full paths to the source),target
(html file to be written),template
(filename of the template which will be used for rendering),data
(most of the context variables seen by this content),doc
(the raw content document source), andurl
(theSELF_URL
value for this content – see below). Note thatMDCONTENT
is not available inside shortcodes. AnMDContentList
is a list object with some convenience methods for filtering and sorting. It is described at the end of this Readme file.- Whatever is defined under
template_context
in thewmk_config.yaml
file (see Configuration file). SELF_URL
: The relative path to the HTML file which the output of the template will be written to.SELF_TEMPLATE
: The path to the current template file (from the template root).ASSETS_MAP
: A map of fingerprinted assets (such as javascript or css files), used by thefingerprint
template filter.site
: A dict-like object containing the variables specified under thesite
key inwmk_config.yaml
.
When templates are rendering markdown (or other) content, they additionally get the following context variables:
CONTENT
: The rendered HTML produced from the source document.RAW_CONTENT
: The original source document.SELF_FULL_PATH
: The full filesystem path to the source document file.SELF_SHORT_PATH
: The path to the source document file relative to the content directory.MTIME
: A datetime object representing the modification time for the source file.DATE
: A datetime object representing the first found value ofdate
,pubdate
,modified_date
,expire_date
, orcreated_date
found in the YAML front matter, or theMTIME
value as a fallback. Since this is guaranteed to be present, it is natural to use it for sorting and generic display purposes.RENDERER
: A callable which enables a template to render markdown inwmk
's own environment. This is mainly so that it is possible to support shortcodes which depend on other markdown content which itself may contain shortcodes. The callable receives a dict containing the keysdoc
(the markdown) anddata
(the context variables) and returns rendered HTML.LOOKUP
: The MakoTemplateLookup
object.page
: A dict-like object containing the variables defined in the YAML meta section at the top of the markdown file, inindex.yaml
files in the markdown file directory and its parent directories insidecontent
, and possibly in YAML files from thedata
directory loaded via theLOAD
directive in the metadata.
For further details on context variables set in the document frontmatter and in
index.yaml
files, see Site, page and nav variables.