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

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