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

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