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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. +++
  2. title = "Sections and Pages"
  3. weight = 20
  4. +++
  5. Pages and sections are actually very similar.
  6. ## Page variables
  7. Gutenberg 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. // the path, split on '/'
  19. components: Array<String>;
  20. permalink: String;
  21. summary: String?;
  22. tags: Array<String>;
  23. category: 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. // `previous` and `next` are only filled if the content can be sorted
  30. previous: Page?;
  31. next: Page?;
  32. // See the Table of contents section below for more details
  33. toc: Array<Header>;
  34. ```
  35. ## Section variables
  36. By default, Gutenberg will try to load `templates/section.html`. If there isn't
  37. one, it will render the built-in template: a blank page.
  38. Whichever template you decide to render, you will get a `section` variable in your template
  39. with the following fields:
  40. ```ts
  41. content: String;
  42. title: String?;
  43. description: String?;
  44. date: String?;
  45. slug: String;
  46. path: String;
  47. // the path, split on '/'
  48. components: Array<String>;
  49. permalink: String;
  50. extra: HashMap<String, Any>;
  51. // Pages directly in this section, sorted if asked
  52. pages: Array<Pages>;
  53. // Direct subsections to this section, sorted by subsections weight
  54. subsections: Array<Section>;
  55. // Naive word count, will not work for languages without whitespace
  56. word_count: Number;
  57. // Based on https://help.medium.com/hc/en-us/articles/214991667-Read-time
  58. reading_time: Number;
  59. // See the Table of contents section below for more details
  60. toc: Array<Header>;
  61. ```
  62. ## Table of contents
  63. Both page and section have a `toc` field which corresponds to an array of `Header`.
  64. A `Header` has the following fields:
  65. ```ts
  66. // The hX level
  67. level: 1 | 2 | 3 | 4 | 5 | 6;
  68. // The generated slug id
  69. id: String;
  70. // The text of the header
  71. title: String;
  72. // A link pointing directly to the header, using the inserted anchor
  73. permalink: String;
  74. // All lower level headers below this header
  75. children: Array<Header>;
  76. ```