Templating
Statik uses Jinja2 as its templating engine, so if you're familiar with Django's templating engine it'll be pretty easy to get into using Statik's.
This guide will only cover the basics of Jinja2 templating. For more details, the Jinja2 Template Designer Documentation will help.
One of the most powerful features of any templating engine is its ability to embed variable values when rendering the templates. Statik template variables can come from two different places:
-
View context - Every view can also define
context
variables (bothstatic
anddynamic
). See the Views documentation on how to configure views. -
Project context - In your
config.yml
file within your project, you can define acontext
variable with bothstatic
anddynamic
context. See the Project configuration documentation for more details.
The above order also gives the order of precedence for your variables (i.e. if a view context variable and project context variable both have the same name, view variables will override project variables).
When defining static context variables, their exact value will be inserted into your template when rendering. Say, for example, your config.yml
file defines the following static context:
# config.yml
# ...
context:
static:
site-title: This is my page title!
And say, for example, your template looks like this:
<!DOCTYPE html>
<html>
<head><title>{{ site_title }}</title></head>
<body>
<!-- page body goes here... -->
</body>
</html>
When your template is rendered, it will contain the following HTML content:
<!DOCTYPE html>
<html>
<head><title>This is my page title!</title></head>
<body>
<!-- page body goes here... -->
</body>
</html>