====== Zola tips ======
Things that are easy to miss when developing for [[https://www.getzola.org|Zola]].
===== Use the "safe" filter in templates =====
You need to pass ''%%{{ page.contents }}%%'' through the ''safe'' filter, thus:
{{ page.contents | safe}}
Content that isn't marked as ''safe'' will have its HTML converted to entities, e.g. ''
{{ page.content | safe }} {# for regular files #}
{{ section.content | safe }} {# for _index.md files #}
This means you'll need different templates (and base templates!) for section pages and regular pages! As an alternative, you can use some logic in the template:
{% if page.title %} {{ page.title }}
{% else %} {{ section.title }}
{% endif %}
**Better yet**, use the following idiom to set ''current'' to the current context, either ''section'' or ''page'':
{% set current = section | default(value=page) %}
{{ current.title }}
It looks like the root ''_index.md'' file can use a template named something other than ''index.html''. Similarly, it looks like non-root ''_index.md'' files can use templates named ''index.html''.
===== Custom front matter variables =====
Custom front matter variables are placed in the ''[extra]'' array:
[extra]
image = "assets/img/12AT7-lum.jpg"
In templates, you can access elements using dot notation:
{{ section.extra.image }}
===== Kludging content segments =====
Many CMSes and some SSGs let you define segments of content that are rendered into named portions in a template.
---
title: Home
---
---heading---
Custom made noise
=================
---lead---
I build what fashionable people call boutique amplifiers.
---body---
Professionally crafted. With heaps of love and soul. [Take a look.]({{pcurl('products')}})
It doesn't look like Zola lets you do this. However, you can kludge this using front matter.
+++
...
[extra]
heading = "# Custom made noise"
lead = "I build what fashionable people call _boutique amplifiers_."
+++
Professionally crafted with heaps of love and soul. [Take a look.](/products)
And in the template:
{{ section.extra.heading | markdown(inline=true) | safe }}
{{ section.extra.lead | markdown | safe }}
{{ section.content | safe }}
{{ section.extra.image }}
===== Marking a menu item as active =====
There may be a better way to do this, but selectively adding a class if the relative path matches seems to work.
No doubt, there are opportunities to stuff some of this into macros and/or partials and/or similar.
===== Breadcrumbs =====
See this [[https://zola.discourse.group/t/breadcrumb/509/3|forum post]], reproduced and re-formatted here in case it goes away:
{% block breadcrumb %}
{% endblock breadcrumb %}