barely makes use of the popular jinja2 templating framework.
The below instructions only scratch the surface of jinja's power, so do yourself a favor and read the documentation!
read full documentationAll your templates live in the templates/
folder inside your devroot. If, for whatever reason, you want to place them somewhere else, set the TEMPLATES_DIR
variable in your config.yaml
.
You can organize your templates freely inside that folder, including the use of subfolders.
You set a template for a page by naming the page's markdown file according to this scheme:
you have the following template: templates/something.html
. To use it, name any markdown file something.md
.
if your template lives in a subfolder, you specify it with a .
: to use templates/subdir/other.html
, name your markdown file subdir.other.md
.
Templates can include or extend other templates:
{% include "subdir/other.html" %}
{% extends "something.html" %}
Page and theme variables can be included in templates by putting the variable names into double curly braces:
1 | {{ variable_name }} |
All the variables you specify in global or page-level config are available. In addition, many plugins add their own variables for you to use.
jinja supports conditional statements:
1 2 3 4 5 | {% if condition %} {{ something }} {% else %} {{ something_else }} {% endif %} |
as well as loops:
1 2 3 | {% for x in list %} {{ x }} {% endfor %} |
among others.