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.7KB

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