章节和页面

页面和部分的模板非常相似。

🔗页面变量

Zola 将尝试加载templates/page.html模板,page.html如果使用了主题的模板或呈现内置模板(空白页面)。

无论您决定呈现哪个模板,您都会page在模板中获得一个包含以下字段的变量:

// The HTML output of the Markdown content
content: String;
title: String?;
description: String?;
date: String?;
updated: String?;
slug: String;
path: String;
draft: Bool;
// the path, split on '/'
components: Array<String>;
permalink: String;
summary: String?;
taxonomies: HashMap<String, Array<String>>;
extra: HashMap<String, Any>;
toc: Array<Header>,
// 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;
// earlier / lighter
lower: Page?;
// later / heavier
higher: Page?;
// Year/month/day is only set if the page has a date and month/day are 1-indexed
year: Number?;
month: Number?;
day: Number?;
// Paths of colocated assets, relative to the content directory
assets: Array<String>;
// The relative paths of the parent sections until the index one, 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>;
// The relative path from the `content` directory to the markdown file
relative_path: String;
// The relative path from the `content` directory to the directory of a colocated index.md markdown file
// Null if the file is not colocated.
colocated_path: String?;
// The language for the page if there is one. Default to the config `default_language`
lang: String;
// Information about all the available languages for that content, including the current page
translations: Array<TranslatedContent>;
// All the pages/sections linking this page: their permalink and a title if there is one
backlinks: Array<{permalink: String, title: String?}>;

🔗节变量

默认情况下,Zola 将尝试templates/index.html其他文件content/_index.md 加载如果没有,它将呈现内置模板(空白页)。templates/section.html_index.md

无论您决定呈现哪个模板,您都会section在模板中获得一个包含以下字段的变量:

// The HTML output of the Markdown content
content: String;
title: String?;
description: String?;
path: String;
// the path, split on '/'
components: Array<String>;
permalink: String;
extra: HashMap<String, Any>;
// Pages directly in this section. By default, the pages are not sorted. Please set the "sort_by"
// variable in the _index.md file of the corresponding section to "date" or "weight" for sorting by
// date and weight, respectively.
pages: Array<Page>;
// Direct subsections to this section, sorted by subsections weight
// This only contains the path to use in the `get_section` built-in function to get
// the actual section object if you need it
subsections: Array<String>;
toc: Array<Header>,
// Unicode word count
word_count: Number;
// Based on https://help.medium.com/hc/en-us/articles/214991667-Read-time
reading_time: Number;
// Paths of colocated assets, relative to the content directory
assets: Array<String>;
// The relative paths of the parent sections until the index one, 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>;
// The relative path from the `content` directory to the markdown file
relative_path: String;
// The language for the section if there is one. Default to the config `default_language`
lang: String;
// Information about all the available languages for that content
translations: Array<TranslatedContent>;
// All the pages/sections linking this page: their permalink and a title if there is one
backlinks: Array<{permalink: String, title: String?}>;
// Whether this section generates a feed or not. Taken from the front-matter if set
generate_feed: bool;

🔗目录

页面和部分模板都有一个toc对应于数组的变量HeaderAHeader具有以下字段:

// The hX level
level: 1 | 2 | 3 | 4 | 5 | 6;
// The generated slug id
id: String;
// The text of the header
title: String;
// A link pointing directly to the header, using the inserted anchor
permalink: String;
// All lower level headers below this header
children: Array<Header>;

🔗翻译内容

页面和部分都有一个translations对应于数组的字段TranslatedContent如果您的网站没有使用多种语言,这将始终是一个空数组。 TranslatedContent具有以下字段:

// 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;
// The path to the markdown file; useful for retrieving the full page through
// the `get_page` function.
path: String;