zola/docs/content/documentation/templates/taxonomies.md
BezPowell 35359fb312
Add generic template fallbacks to taxonomies (#1651)
* Split checking for theme template off into separate function

Allows to check for fallbacks elsewhere in the code, without attempting to actually render the template.

* Add template fallback checking to taxonomy pages.

* Add template fallback checking to paginated taxonomies

Requires passing additional arguments to Paginator::from_taxonomy, which may not be desirable.

* Update documentation to reflect taxonomy template fallbacks.

* Update generic taxonomy template names.

* Make check_template_fallbacks() return &str.

* Add tests for check_template_fallbacks
2021-11-29 09:54:16 +01:00

74 lines
1.6 KiB
Markdown

+++
title = "Taxonomies"
weight = 40
+++
Zola will look up the following, taxon-specific files in the `templates` directory:
- `$TAXONOMY_NAME/single.html`
- `$TAXONOMY_NAME/list.html`
if they are not found, it will attempt to fall back on the following generic template files:
- `taxonomy_single.html`
- `taxonomy_list.html`
First, `TaxonomyTerm` has the following fields:
```ts
name: String;
slug: String;
path: String;
permalink: String;
pages: Array<Page>;
```
and `TaxonomyConfig` has the following fields:
```ts
name: String,
paginate_by: Number?;
paginate_path: String?;
feed: Bool;
lang: String;
permalink: String;
```
### Taxonomy list (`list.html`)
This template is never paginated and therefore gets the following variables in all cases.
```ts
// The site config
config: Config;
// The data of the taxonomy, from the config
taxonomy: TaxonomyConfig;
// The current full permalink for that page
current_url: String;
// The current path for that page
current_path: String;
// All terms for that taxonomy
terms: Array<TaxonomyTerm>;
// The lang of the current page
lang: String;
```
### Single term (`single.html`)
```ts
// The site config
config: Config;
// The data of the taxonomy, from the config
taxonomy: TaxonomyConfig;
// The current full permalink for that page
current_url: String;
// The current path for that page
current_path: String;
// The current term being rendered
term: TaxonomyTerm;
// The lang of the current page
lang: String;
```
A paginated taxonomy term will also get a `paginator` variable; see the
[pagination page](@/documentation/templates/pagination.md) for more details.