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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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/index.html` for `content/_index.md`
  38. and `templates/section.html` for others `_index.md` files. If there isn't
  39. one, it will render the built-in template: a blank page.
  40. Whichever template you decide to render, you will get a `section` variable in your template
  41. with the following fields:
  42. ```ts
  43. content: String;
  44. title: String?;
  45. description: String?;
  46. date: String?;
  47. slug: String;
  48. path: String;
  49. // the path, split on '/'
  50. components: Array<String>;
  51. permalink: String;
  52. extra: HashMap<String, Any>;
  53. // Pages directly in this section, sorted if asked
  54. pages: Array<Pages>;
  55. // Direct subsections to this section, sorted by subsections weight
  56. subsections: Array<Section>;
  57. // Unicode word count
  58. word_count: Number;
  59. // Based on https://help.medium.com/hc/en-us/articles/214991667-Read-time
  60. reading_time: Number;
  61. // See the Table of contents section below for more details
  62. toc: Array<Header>;
  63. ```
  64. ## Table of contents
  65. Both page and section have a `toc` field which corresponds to an array of `Header`.
  66. A `Header` has the following fields:
  67. ```ts
  68. // The hX level
  69. level: 1 | 2 | 3 | 4 | 5 | 6;
  70. // The generated slug id
  71. id: String;
  72. // The text of the header
  73. title: String;
  74. // A link pointing directly to the header, using the inserted anchor
  75. permalink: String;
  76. // All lower level headers below this header
  77. children: Array<Header>;
  78. ```