You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pages-sections.md 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. +++
  2. title = "Sections and Pages"
  3. weight = 20
  4. +++
  5. Templates for pages and sections are very similar.
  6. ## Page variables
  7. Zola will try to load the `templates/page.html` template, the `page.html` template of the theme if one is used
  8. or render the built-in template (a blank page).
  9. Whichever template you decide to render, you will get a `page` variable in your template
  10. with the following fields:
  11. ```ts
  12. content: String;
  13. title: String?;
  14. description: String?;
  15. date: String?;
  16. slug: String;
  17. path: String;
  18. draft: Bool;
  19. // the path, split on '/'
  20. components: Array<String>;
  21. permalink: String;
  22. summary: String?;
  23. taxonomies: HashMap<String, Array<String>>;
  24. extra: HashMap<String, Any>;
  25. toc: Array<Header>,
  26. // Naive word count, will not work for languages without whitespace
  27. word_count: Number;
  28. // Based on https://help.medium.com/hc/en-us/articles/214991667-Read-time
  29. reading_time: Number;
  30. // `earlier` and `later` are only populated if the section variable `sort_by` is set to `date`
  31. // and only set when rendering the page itself
  32. earlier: Page?;
  33. later: Page?;
  34. // `heavier` and `lighter` are only populated if the section variable `sort_by` is set to `weight`
  35. // and only set when rendering the page itself
  36. heavier: Page?;
  37. lighter: Page?;
  38. // Year/month/day is only set if the page has a date and month/day are 1-indexed
  39. year: Number?;
  40. month: Number?;
  41. day: Number?;
  42. // Paths of colocated assets, relative to the content directory
  43. assets: Array<String>;
  44. // The relative paths of the parent sections until the index onef for use with the `get_section` Tera function
  45. // The first item is the index section and the last one is the parent section
  46. // This is filled after rendering a page content so it will be empty in shortcodes
  47. ancestors: Array<String>;
  48. // The relative path from the `content` directory to the markdown file
  49. relative_path: String;
  50. // The language for the page if there is one. Default to the config `default_language`
  51. lang: String;
  52. // Information about all the available languages for that content
  53. translations: Array<TranslatedContent>;
  54. ```
  55. ## Section variables
  56. By default, Zola will try to load `templates/index.html` for `content/_index.md`
  57. and `templates/section.html` for other `_index.md` files. If there isn't
  58. one, it will render the built-in template (a blank page).
  59. Whichever template you decide to render, you will get a `section` variable in your template
  60. with the following fields:
  61. ```ts
  62. content: String;
  63. title: String?;
  64. description: String?;
  65. path: String;
  66. // the path, split on '/'
  67. components: Array<String>;
  68. permalink: String;
  69. extra: HashMap<String, Any>;
  70. // Pages directly in this section, sorted if asked
  71. pages: Array<Page>;
  72. // Direct subsections to this section, sorted by subsections weight
  73. // This only contains the path to use in the `get_section` Tera function to get
  74. // the actual section object if you need it
  75. subsections: Array<String>;
  76. toc: Array<Header>,
  77. // Unicode word count
  78. word_count: Number;
  79. // Based on https://help.medium.com/hc/en-us/articles/214991667-Read-time
  80. reading_time: Number;
  81. // Paths of colocated assets, relative to the content directory
  82. assets: Array<String>;
  83. // The relative paths of the parent sections until the index onef for use with the `get_section` Tera function
  84. // The first item is the index section and the last one is the parent section
  85. // This is filled after rendering a page content so it will be empty in shortcodes
  86. ancestors: Array<String>;
  87. // The relative path from the `content` directory to the markdown file
  88. relative_path: String;
  89. // The language for the section if there is one. Default to the config `default_language`
  90. lang: String;
  91. // Information about all the available languages for that content
  92. translations: Array<TranslatedContent>;
  93. ```
  94. ## Table of contents
  95. Both page and section templates have a `toc` variable that corresponds to an array of `Header`.
  96. A `Header` has the following fields:
  97. ```ts
  98. // The hX level
  99. level: 1 | 2 | 3 | 4 | 5 | 6;
  100. // The generated slug id
  101. id: String;
  102. // The text of the header
  103. title: String;
  104. // A link pointing directly to the header, using the inserted anchor
  105. permalink: String;
  106. // All lower level headers below this header
  107. children: Array<Header>;
  108. ```
  109. ## Translated content
  110. Both pages and sections have a `translations` field that corresponds to an array of `TranslatedContent`. If your
  111. site is not using multiple languages, this will always be an empty array.
  112. `TranslatedContent` has the following fields:
  113. ```ts
  114. // The language code for that content, empty if it is the default language
  115. lang: String?;
  116. // The title of that content if there is one
  117. title: String?;
  118. // A permalink to that content
  119. permalink: String;
  120. ```