Templates¶
Content is then rendered using Jinja2 templates. Templates can have any
extension, and that extension will carry over to the generated files. So if you
want to generate an html file, then your default template would be named
default.html, and be in the templates directory.
To choose what template a content file should use, specify the type metadata
field. For more information, see the section on content.
Various variables relating to the site and the current page are provided to the template system. For example:
{% extends "base.html" %}
{% block content %}
<h1>{{ page.title }}</h1>
{{ page.content }}
{% endblock %}
There are two main objects available to the templater: site, and page.
These variables, and the following attributes, are guaranteed to exist, and be
decently well formed, unless otherwise noted.
site¶
site.title- The title of the site, defined in the config file by thesite_titleoption.site.datetime- The last time the site was generated, as a full date and time.site.date- The date of the last site generation.site.time- The time of day of the last site generation.site.pages- All the pages on the site, in a flat list.site.slugs- A dictionary where the key is the slug of the page, and the value is the page itself.site.tags- A dictionary. The keys are tag names, and each value is a list of pages that have that tag..{tag: [list of pages]}.site.categories- The top level categories of the site as a dictionary. They keys are the category names, and the values are the main page of that category. {category: main page}.site.author- Only defined if it is specified with the author field in the config file. If multiple authors are specified, this is the first one.site.authors- Likesite.author, but as a list of all authorers specified.
page¶
Each of these may be set or overwritten in the YAML header on each content file, unless otherwise stated.
page.title- The title of the page.page.slug- Used for making urls. Usually a lower case, no punctuation, no whitespace version of the title. Will be auto generated from title if not specified.page.author- The first author of the page, as anAuthorobject. If unspecified in the YAML header, the site default will be used, if that is unspecified, the object will still exist, but will haveNonefor it's attributes. If multiple authors are specified, this will be the first one.page.authors- Likepage.author, except as a list of all specifed authors.page.published- Whether the page is to be generated and put in the variables of other pages. If this is false, the page won't be processed, or available to any templates.page.datetime- The datetime content's metadata. Usually the date the content was written or last updated.page.date- Like above, but as a date object (no time information).page.time- Like above, but only the time of day.page.url- The root-relative url that the page will be at. Generated by theurl_pattern, but can by manually overwritten.page.subpages- All the direct children of this page as a list.