+++ title = "Zola Cookbook" description = "Snippets I've developed that I want to keep" date = 2022-04-27T18:00:00+00:00 updated = 2022-04-27T18:00:00+00:00 template = "docs/section.html" sort_by = "weight" weight = 5 draft = false [taxonomies] documentation=["Reference"] categories=["Web Development", "Static Site Generation", "Zola"] +++ [Zola](../zola) is the static site generator I use for most of my websites that don't require much dynamic functionality. ## Generating Nested Lists from Data Example data: ```html { "definitions": [ { "dt": "undefined", "dd": " the thing is undefined." }, { "dt": "defined", "dd": " the thing is defined.", definitions: [ { "dt": "truthy", "dd": "the defined thing is truthy" }, { "dt": "falsy", "dd": "the defined thing is falsy" } ]} ] } ``` Tera macro to render a nested list: ``` {% macro definition_body(source) %}
{% for entry in source %}
{{ entry.dt | safe }}
{{ entry.dd | safe }} {% if entry.definitions %} {{ self::definition_body(source=entry.definitions) }} {% endif %}
{% endfor %}
{% endmacro %} ``` Zola shortcode to import the macro template into Markdown and start the render: ``` {%- import 'macros/definition_body.html' as renderer -%}
{% set content = load_data(path=source) %} {{ renderer::definition_body(source=content.definitions) }}
``` Invocation in Markdown file, providing the data source: ``` {‎{ definition_list(source="@/docs/zola/definitions.json") }} ```