Home Blag Links Wireguard About

Zola with extra variables

2021-01-24

I use Zola for static site generation. Seems very useful so far.

Had a problem with custom variables in Zola pages. Took me a bit to figure out that custom variables need to go into an [extra] section of the individual page's front matter, as the official documentation is very quiet about this. In fact, there is a section for [extra], but there is no documentation about it whatsoever.

It goes like this:

+++
(...)
[extra]
mycrazyvar = "foo is a bar"
(...)
+++
Here comes some markdown.
(...)

This can be used within templates with 'dot-namespace-notation' like {{ peer.extra.mycrazyvar }}:

{% for peer in section.pages %}
(...)
{{ peer.extra.mycrazyvar }}
(...)