Template variables
- Version:
- 8.3.1
Variables available in templates are listed below.
This list is maintained by humans, so it may not always be perfect.
Variables whose types are marked with
?
may not always be available or may be None in some cases.Templates usually do not have access to the original TranslatableSetting variables, only to the current locale version (except
NAVIGATION_LINKS
).For function and setting documentation, please consult code documentation and default configuration respectively.
Templates often create their own functions (macros), and import macros from other templates. Those macros are not listed here.
This list has a partial documentation of post objects, but no other objects. For full docs, please consult the code, or auto-generated code docs on ReadTheDocs.
Variables and functions come from three places:
the global context
the local context of a page
the templates themselves and the templates they import
Global variables¶
Some variables on the global variables list may be None (the ?
symbol is not used).
Name |
Type |
Description |
---|---|---|
|
function |
|
|
function |
|
|
TranslatableSetting[str] |
|
|
bool |
False |
|
TranslatableSetting[str] |
|
|
str |
|
|
TranslatableSetting[str] |
|
|
TranslatableSetting[str] |
|
|
str |
|
|
TranslatableSetting[str] |
|
|
function |
|
|
function |
|
|
str |
|
|
str |
|
|
TranslatableSetting[str] |
|
|
dict |
data files (from the |
|
int |
|
|
TranslatableSetting[str] |
|
|
function |
|
|
TranslatableSetting[str] |
|
|
tuple |
|
|
TranslatableSetting[str] |
|
|
bool |
|
|
bool |
|
|
dict |
alias for |
|
bool |
True if custom.css exists |
|
list[str] |
|
|
list[str] |
|
|
list[str] |
|
|
bool |
|
|
int |
|
|
str |
|
|
TranslatableSetting[str] |
|
|
str |
|
|
TranslatableSetting[str] |
|
|
str |
|
|
TranslatableSetting[str] |
|
|
str |
|
|
dict[dict[str, str]] |
translated messages ( |
|
bool |
|
|
defaultdict[str, str] |
dictionary of available Moment.js locales |
|
bool |
|
|
TranslatableSetting |
|
|
TranslatableSetting |
|
|
bool |
whether or not Jupyter CSS is needed by this site |
|
function |
|
|
str |
|
|
TranslatableSetting[str] |
|
|
function |
|
|
bool |
|
|
bool |
|
|
bool |
whether or not a comment system is configured |
|
TranslatableSetting[str] |
|
|
function |
|
|
function |
|
|
function |
|
|
dict[str, TemplateHookRegistry] |
Template hooks registered by plugins |
|
str |
|
|
dict |
|
|
tzinfo |
Timezone object (represents the configured timezone) |
|
dict[str, str] |
|
|
dict |
|
|
function |
|
|
str |
|
|
bool |
|
|
bool |
|
|
bool |
|
|
str? |
|
|
str? |
|
Per-page local variables¶
Those variables are available on all pages, but their contents are dependent on page contents.
Name |
Type |
Description |
---|---|---|
|
str |
Description of the page |
|
bool |
Whether or not the language is left-to-right |
|
str |
Current language |
|
list[str] |
List of strings that identify the type of this page (docs) |
|
str |
Title of the page (taken from post, config, etc.) |
|
function |
Wrapper over |
|
function |
Strips HTML tags (Mako only) |
|
list |
Breadcrumbs for this page |
Variables available in post pages (post.tmpl
, page.tmpl
etc.)¶
Name |
Type |
Description |
---|---|---|
|
Post |
The post object |
|
str |
Permanent link to the post |
|
bool |
True for posts, |
Variables available in post lists¶
Name |
Type |
Description |
---|---|---|
|
list[Post] |
List of post objects that appear in this list |
|
str |
Link to previous page |
|
str |
Link to next page |
Variables available in indexes¶
Name |
Type |
Description |
---|---|---|
|
list[Post] |
List of post objects that appear in this list |
|
bool |
|
|
bool |
|
|
int |
Number of current page |
|
list[str] |
Links to different pages |
|
str |
Link to previous page |
|
str |
Link to next page |
|
str |
Link to previous page as an Atom feed |
|
str |
Link to next page as an Atom feed |
|
bool |
Whether or not previous and next links should be reversed ( |
|
bool |
Whether or not this is the front-most index (page 0) |
Variables available in taxonomies¶
Variable names enclosed in {}
are dependent on the taxonomy.
Taxonomy |
Variable |
Value |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unavailable (None) |
|
|
|
|
|
|
|
|
|
Templates and settings used by taxonomies¶
Taxonomy |
Has hierarchy |
List (one classification) template |
Index (one classification) template |
Overview (list of classifications) template |
Subcategories list template |
List is an index |
Show as list of subcategories |
---|---|---|---|---|---|---|---|
(default settings) |
no |
tagindex.tmpl |
tagindex.tmpl |
list.tmpl |
taxonomy_list.tmpl (does not exist) |
no |
no |
|
yes (0-3 levels) |
list_post.tmpl |
archiveindex.tmpl |
list.tmpl |
list.tmpl |
|
|
|
no |
author.tmpl |
authorindex.tmpl |
authors.tmpl |
n/a |
|
no |
|
yes |
tag.tmpl |
tagindex.tmpl |
tags.tmpl (with tags) |
n/a |
|
n/a |
|
no |
n/a |
index.tmpl |
n/a |
n/a |
yes |
no |
|
yes |
list.tmpl |
n/a |
n/a |
n/a |
no |
no |
|
no |
tag.tmpl |
tagindex.tmpl |
tags.tmpl (with categories) |
n/a |
|
no |
Classification overviews¶
Hierarchy-related variables are available if and only if has_hierarchy
is True.
Name |
Type |
Description |
---|---|---|
|
str |
List of classifications |
|
list |
List of items (name, link) |
|
list |
List of items (name, link, number of posts) |
|
list? |
List of hierarchies (name, full name, path, link, indent levels, indent to change before, indent to change after) |
|
list? |
List of hierarchies, with added counts (name, full name, path, link, indent levels, indent to change before, indent to change after, number of children, number of posts) |
|
bool |
Value of |
|
str |
Permanent link to page |
Classification pages (lists)¶
Name |
Type |
Description |
---|---|---|
|
str |
The classification name |
|
list? |
List of items for |
|
list[Post]? |
List of items for other templates |
|
str |
Permanent link to page |
|
list[tuple] |
List of triples |
Index-style classification pages have kind
in addition to the usual index variables.
Subclassification page¶
Name |
Type |
Description |
---|---|---|
|
list? |
List of items |
|
str |
Permanent link to page |
|
list[tuple] |
List of triples |
Hierarchical lists¶
The indenting information can be used to render the items as a tree. The values have the following meanings:
indent levels
is a list of pairs(current_i, count_i)
giving the current position (0
, ...,count_i-1
) and maximum (count_i
) in the hierarchy leveli
;
indent to change before
is the difference of hierarchy levels between the previous and the current item; positive values indicate that the current item is indented further in and can be used to open HTML tags before the item;
indent to change after
is the difference of hierarchy levels between the current and the next item; negative values indicate that the current item is indented further in and can be used to close HTML tags after the item.
Example:
+--- levels:[(0,3)], before:1, after:0 +-+- levels:[(1,3)], before:0, after:1 | +--- levels:[(1,3), (0,2)], before:1, after:0 | +-+- levels:[(1,3), (1,2)], before:0, after:1 | +--- levels:[(1,3), (1,2), (0, 1)], before:1, after:-2 +-+- levels:[(2,3)], before:-2, after:1 +- levels:[(2,3), (0,1)], before:1, after:-2
See tags.tmpl
in the base themes for examples on how to render a tree as nested unordered lists in HTML.
Variables available in archives¶
The archive navigation variables are available only if create_archive_navigation
is True.
Name |
Type |
Description |
---|---|---|
|
str |
Always |
|
str? |
Name of the archive (only if using indexes) |
|
bool |
|
|
bool |
Whether or not archive navigation is available |
|
str? |
Link to the archive one level up |
|
str? |
Name of the archive one level up |
|
str? |
Link to the previous archive |
|
str? |
Name of the previous archive |
|
str? |
Link to the next archive |
|
str? |
Name of the next archive |
|
int? |
Level of the archive |
|
list |
List of tuples |
Variables available in category pages¶
Name |
Type |
Description |
---|---|---|
|
str |
Always |
|
str |
Category name |
|
list[str] |
Category hierarchy |
|
str? |
Link to RSS (HTML fragment, only if using indexes) |
|
list |
List of subcategories (contains name, link tuples) |
|
str |
Friendly category name |
|
list[tuple] |
List of tuples |
Variables available in galleries¶
Name |
Type |
Description |
---|---|---|
|
list |
Breadcrumbs for this page |
|
bool |
Whether or not comments are enabled in galleries |
|
list |
List of folders (contains path, title tuples) |
|
str |
Permanent link to this page |
|
list |
Photo array (contains dicts with image data: url, url_thumb, title, size{w, h}) |
|
str |
Photo array in JSON format |
|
Post? |
The Post object for this gallery |
|
int |
|
Variables available in listings¶
Name |
Type |
Description |
---|---|---|
|
str |
Highlighted source code (HTML fragment) |
|
list |
Breadcrumbs for this page |
|
list[str] |
List of subfolders |
|
list[str] |
List of files in the folder |
|
str |
Link to the source file |
Variables available in tag pages¶
Name |
Type |
Description |
---|---|---|
|
str |
Always |
|
str |
Tag name |
|
list[tuple] |
List of tuples |
Variables available in shortcodes¶
The global context is available in templated shortcodes.
Name |
Type |
Description |
---|---|---|
|
str |
Current language |
|
list[str] |
Arguments given to the shortcode |
|
str |
Shortcode contents |
|
Post |
Post object (if available) |
|
str? |
file name, if |
Variables available in post lists¶
The global context is NOT available in post lists.
Name |
Type |
Description |
---|---|---|
|
list[Post] |
Posts that are on the list |
|
str |
Current language |
|
str |
The date format for current language |
|
str |
GUID of post list |
|
dict |
The messages dictionary |
|
function |
|
Post object attributes¶
Usable anywhere post objects are accessible.
This list only includes variables that make sense for templates. Some function signatures have been shortened to save space, ?
means the argument has default value.
More docs: nikola.post.Post on ReadTheDocs. Check out the source of the Post class as well.
Name |
Type |
Description |
---|---|---|
|
list[str] |
All tags for the post |
|
str |
Localized author or |
|
str |
|
|
bool |
If category was set by |
|
? |
Access to post data |
|
datetime |
Date of post (from meta) |
|
str |
Description of post (from meta) |
|
str |
Destination path of post |
|
str |
Format a date (default: post date) |
|
str |
Format the last update date |
|
str |
GUID of post (used for feeds) |
|
bool |
If the post has math |
|
bool |
If the post has a pretty URL |
|
bool |
If the post is a draft |
|
bool |
If the post is not a page |
|
bool |
If the post is private |
|
bool |
If the post is available in (translated to) a given language |
|
bool |
If the post uses two-file metadata |
|
? |
Metadata of the post (assumes current language) |
|
Post |
Next post in the order |
|
int |
Paragraph count for a post |
|
str |
Permanent link for a post |
|
str |
Source path, without extension |
|
str |
Post status meta field (published, featured, private, draft) |
|
Post |
Previous post in the order |
|
str |
Preview image of the post |
|
bool |
True if the post is not yet published (due to date) |
|
int |
Approximate reading time in minutes (220 wpm) |
|
int |
Paragraph count after the teaser |
|
int |
Reading time after the teaser |
|
str |
Absolute link to the post's source |
|
list[str] |
Tags for the current language |
|
list[str] |
Tags for a given language |
|
str |
The text of a post |
|
str |
Localized title of post |
|
list[str] |
List of languages of post |
|
datetime |
Date of last update (from meta) |
|
bool |
If this post should be displayed in feeds |