Templating
Posty uses Jinja for its templates. Your templates should live in the
templates/ directory in your site root.
Template Files
page.html post_base.html post.html posts.html redirect.html
There are a few required templates to be able to generate a site. Each of these should live in the templates/ directory in your site root.
page.html
This renders a single Page.
The following variables are available:
post.html
Renders a single Post.
These variables are available:
posts.html
Renders a list of Posts. This is used both for rendering N number of posts in a series as pages, as well as rendering the same thing for each tag.
These variables are available:
redirect.html
This is a special optional template that is used if Posty 1.x URL compatibility
is turned on. The only variable passed in is a url which is the real URL
of the post.
This is provided for you if you run posty init and it’s unlikely that
you’ll need to modify it.
Template Variables
These are the variables and the fields available on each that you can use in your templates. Note that not all variables are available in all tempaltes, see above for which ones are.
site
This is a representation of the site as a whole. Note that if you’re trying to access a list of posts, you should likely use the
It has the following fields available on it:
pages- The list of all Pages on the siteposts- The list of all Posts on the site, in reverse chronological ordertags- The list of all tags found in Posts on the siteconfig- The configuration loaded from the Config File. See Config Variables for details on what fields are available.copyright- The copyright string for the site, based on the year of your earliest post, the year of the latest post, and theauthorset in the Config File.
page
The representation of the Page being rendered.
It has these fields and functions available on it:
title- The title of the pagebody- The body text of the pageparent- The parent page to this page. Will beNoneif this is a top-level page.slug- The slugified title of the page, as used in the URLurl()- Function which returns the absolute URL to this page
post
The represenatation of the Post being rendererd.
It has these fields and functions available on it:
titledatetags- The list of tags for this postblurb- The blurb (summary) of this post as defined in the YAML file. If no blurb was set, then this is identical to the body.body- The body of this post as defined in the YAML file. This will include theblurbif one was set in the YAML file.slug- The slugified title of this post, as used in the URLurl()- Function which returns the absolute URL to this post
posts
A list of post objects.
next_page_url
If not null, provides the absolute URL to the next page of post items.
prev_page_url
If not null, provides the absolute URL to the previous page of post items.
Jinja Filters
These functions are available as Jinja filters in all templates.
markdown
This filter takes text and returns the Markdown-rendered version of it.
Usage: {{ post.body | markdown }}
media_url
This filter takes a URL relative to the media/ directory and returns an
abosulte URL to that thing.
For example, if your base_url in your config is https://example.org/site/:
{{ "css/index.css" | media_url }}
Returns https://example.org/site/media/css/index.css.
absolute_url
This filter works in a similar way to media_url, but instead returning
the absolute URL for an arbitrary relative URL. It does this by concatenating
the base_url from config with the given relative URL.
This is handy if you’re directly linking to a page from some other page or a post.
Usage: {{ "/some-page-name/" | absolute_url }}