2017-09-27 14:37:17 +00:00
|
|
|
+++
|
2017-10-19 11:48:50 +00:00
|
|
|
title = "Sections and Pages"
|
2017-09-27 14:37:17 +00:00
|
|
|
weight = 20
|
|
|
|
+++
|
|
|
|
|
2019-11-26 19:30:30 +00:00
|
|
|
Templates for pages and sections are very similar.
|
2017-09-27 14:37:17 +00:00
|
|
|
|
|
|
|
## Page variables
|
2018-10-18 21:09:32 +00:00
|
|
|
Zola will try to load the `templates/page.html` template, the `page.html` template of the theme if one is used
|
2019-11-26 19:30:30 +00:00
|
|
|
or render the built-in template (a blank page).
|
2017-09-27 14:37:17 +00:00
|
|
|
|
|
|
|
Whichever template you decide to render, you will get a `page` variable in your template
|
|
|
|
with the following fields:
|
|
|
|
|
|
|
|
|
|
|
|
```ts
|
|
|
|
content: String;
|
|
|
|
title: String?;
|
|
|
|
description: String?;
|
|
|
|
date: String?;
|
|
|
|
slug: String;
|
|
|
|
path: String;
|
2017-11-01 13:53:28 +00:00
|
|
|
draft: Bool;
|
2017-10-31 15:41:31 +00:00
|
|
|
// the path, split on '/'
|
|
|
|
components: Array<String>;
|
2017-09-27 14:37:17 +00:00
|
|
|
permalink: String;
|
|
|
|
summary: String?;
|
2018-08-12 12:09:46 +00:00
|
|
|
taxonomies: HashMap<String, Array<String>>;
|
2017-09-27 14:37:17 +00:00
|
|
|
extra: HashMap<String, Any>;
|
2019-10-14 13:12:19 +00:00
|
|
|
toc: Array<Header>,
|
2017-09-27 14:37:17 +00:00
|
|
|
// Naive word count, will not work for languages without whitespace
|
|
|
|
word_count: Number;
|
|
|
|
// Based on https://help.medium.com/hc/en-us/articles/214991667-Read-time
|
|
|
|
reading_time: Number;
|
2018-07-29 20:53:42 +00:00
|
|
|
// `earlier` and `later` are only populated if the section variable `sort_by` is set to `date`
|
2019-01-21 16:54:44 +00:00
|
|
|
// and only set when rendering the page itself
|
2018-07-29 20:53:42 +00:00
|
|
|
earlier: Page?;
|
|
|
|
later: Page?;
|
|
|
|
// `heavier` and `lighter` are only populated if the section variable `sort_by` is set to `weight`
|
2019-01-21 16:54:44 +00:00
|
|
|
// and only set when rendering the page itself
|
2018-07-29 20:53:42 +00:00
|
|
|
heavier: Page?;
|
|
|
|
lighter: Page?;
|
2018-05-30 12:08:35 +00:00
|
|
|
// Year/month/day is only set if the page has a date and month/day are 1-indexed
|
|
|
|
year: Number?;
|
|
|
|
month: Number?;
|
|
|
|
day: Number?;
|
2018-06-25 17:13:21 +00:00
|
|
|
// Paths of colocated assets, relative to the content directory
|
|
|
|
assets: Array<String>;
|
2018-10-18 13:54:51 +00:00
|
|
|
// The relative paths of the parent sections until the index onef for use with the `get_section` Tera function
|
|
|
|
// The first item is the index section and the last one is the parent section
|
|
|
|
// This is filled after rendering a page content so it will be empty in shortcodes
|
|
|
|
ancestors: Array<String>;
|
2018-10-18 16:00:39 +00:00
|
|
|
// The relative path from the `content` directory to the markdown file
|
|
|
|
relative_path: String;
|
2019-01-29 18:20:03 +00:00
|
|
|
// The language for the page if there is one. Default to the config `default_language`
|
|
|
|
lang: String;
|
2019-01-04 19:31:31 +00:00
|
|
|
// Information about all the available languages for that content
|
|
|
|
translations: Array<TranslatedContent>;
|
2017-09-27 14:37:17 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## Section variables
|
2018-10-18 21:09:32 +00:00
|
|
|
By default, Zola will try to load `templates/index.html` for `content/_index.md`
|
2019-11-26 19:30:30 +00:00
|
|
|
and `templates/section.html` for other `_index.md` files. If there isn't
|
|
|
|
one, it will render the built-in template (a blank page).
|
2017-09-27 14:37:17 +00:00
|
|
|
|
|
|
|
Whichever template you decide to render, you will get a `section` variable in your template
|
|
|
|
with the following fields:
|
|
|
|
|
|
|
|
|
|
|
|
```ts
|
|
|
|
content: String;
|
|
|
|
title: String?;
|
|
|
|
description: String?;
|
|
|
|
path: String;
|
2017-10-31 15:41:31 +00:00
|
|
|
// the path, split on '/'
|
|
|
|
components: Array<String>;
|
2017-09-27 14:37:17 +00:00
|
|
|
permalink: String;
|
|
|
|
extra: HashMap<String, Any>;
|
|
|
|
// Pages directly in this section, sorted if asked
|
2019-12-26 12:55:54 +00:00
|
|
|
pages: Array<Page>;
|
2017-09-27 14:37:17 +00:00
|
|
|
// Direct subsections to this section, sorted by subsections weight
|
2018-10-15 20:28:25 +00:00
|
|
|
// This only contains the path to use in the `get_section` Tera function to get
|
|
|
|
// the actual section object if you need it
|
|
|
|
subsections: Array<String>;
|
2019-10-14 13:12:19 +00:00
|
|
|
toc: Array<Header>,
|
2018-05-16 21:52:26 +00:00
|
|
|
// Unicode word count
|
2017-09-27 14:37:17 +00:00
|
|
|
word_count: Number;
|
|
|
|
// Based on https://help.medium.com/hc/en-us/articles/214991667-Read-time
|
|
|
|
reading_time: Number;
|
2018-08-10 13:59:03 +00:00
|
|
|
// Paths of colocated assets, relative to the content directory
|
|
|
|
assets: Array<String>;
|
2018-10-18 13:54:51 +00:00
|
|
|
// The relative paths of the parent sections until the index onef for use with the `get_section` Tera function
|
|
|
|
// The first item is the index section and the last one is the parent section
|
|
|
|
// This is filled after rendering a page content so it will be empty in shortcodes
|
|
|
|
ancestors: Array<String>;
|
2018-10-18 16:00:39 +00:00
|
|
|
// The relative path from the `content` directory to the markdown file
|
|
|
|
relative_path: String;
|
2019-01-29 18:20:03 +00:00
|
|
|
// The language for the section if there is one. Default to the config `default_language`
|
|
|
|
lang: String;
|
2019-01-04 19:31:31 +00:00
|
|
|
// Information about all the available languages for that content
|
|
|
|
translations: Array<TranslatedContent>;
|
2017-09-27 14:37:17 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## Table of contents
|
|
|
|
|
2019-11-26 19:30:30 +00:00
|
|
|
Both page and section templates have a `toc` variable that corresponds to an array of `Header`.
|
2017-09-27 14:37:17 +00:00
|
|
|
A `Header` has the following fields:
|
|
|
|
|
|
|
|
```ts
|
2017-10-01 03:51:43 +00:00
|
|
|
// The hX level
|
2017-09-27 14:37:17 +00:00
|
|
|
level: 1 | 2 | 3 | 4 | 5 | 6;
|
2017-10-01 03:51:43 +00:00
|
|
|
// The generated slug id
|
2017-09-27 14:37:17 +00:00
|
|
|
id: String;
|
2017-10-01 03:51:43 +00:00
|
|
|
// The text of the header
|
2017-09-27 14:37:17 +00:00
|
|
|
title: String;
|
2017-10-01 03:51:43 +00:00
|
|
|
// A link pointing directly to the header, using the inserted anchor
|
2017-09-27 14:37:17 +00:00
|
|
|
permalink: String;
|
2017-10-01 03:51:43 +00:00
|
|
|
// All lower level headers below this header
|
2017-09-27 14:37:17 +00:00
|
|
|
children: Array<Header>;
|
|
|
|
```
|
2019-01-04 19:31:31 +00:00
|
|
|
|
|
|
|
## Translated content
|
|
|
|
|
2019-11-26 19:30:30 +00:00
|
|
|
Both pages and sections have a `translations` field that corresponds to an array of `TranslatedContent`. If your
|
|
|
|
site is not using multiple languages, this will always be an empty array.
|
|
|
|
`TranslatedContent` has the following fields:
|
2019-01-04 19:31:31 +00:00
|
|
|
|
|
|
|
```ts
|
|
|
|
// The language code for that content, empty if it is the default language
|
|
|
|
lang: String?;
|
|
|
|
// The title of that content if there is one
|
|
|
|
title: String?;
|
|
|
|
// A permalink to that content
|
|
|
|
permalink: String;
|
|
|
|
```
|
|
|
|
|