Theme variables
This theme makes a number of variables related to chapters and parts available to markdown files and Liquid templates.
The chapter-vars.html
helper sets a number of variables for this theme,
which can be accessed in markdown files and Liquid templates.
It can also render the variables for inspection.
Parameters:
id
: Thepage.id
of the chapter page for which to set variables.slug
: Thepage.slug
of the chapter page for which to set variables (ignored ifid
is passed).withnum
: For performance reasons, chapter and part numbers are not computed unlesswithnum
istrue
. (To compute only chapter or only part numbers, setwithnum=part
orwithnum=chapter
instead.)inspect
: If true, render the variables to the page, for debugging.
To set variables for the current chapter:
{% include chapter-vars.html id=page.id withnum="true" %}
Then access them like this:
**Chapter number:** {{ chapter_num }}
…which renders: Chapter number: 4
To inspect all the variables, for debugging:
{% include chapter-vars.html id=page.id inspect="true" withnum="true" %}
…which renders this:
chapter inherits from page
The
chapter
object is identical to the
built-in Jekyll
page
object with the same
id.
|
|
---|---|
page.id | /variables |
chapter.id | /variables |
chapter.title | Theme variables |
chapter.slug | variables |
chapter.url | /variables.html |
... | See page documentation |
Chapter metadata | |
chapter_is_draft | false |
chapter_is_visible | true |
chapter_is_part_index | false |
chapter_sort_index | 060 |
chapter_sort_index_ext | |
Part metadata | |
part_label | Repo setup |
part_unnumbered | false |
part_is_draft | false |
part_folder | 010-repo-setup |
part_sort_index | 010 |
part_sort_index_ext | |
part_index_chapter.url | /theme.html |
Numbering | |
chapter_num | 4 |
part_num | 1 |
To set variables for a different chapter,
you can pass the chapter’s slug
,
like this:
{% include chapter-vars.html slug="contents" withnum="true" inspect="true" %}
…which renders this:
chapter inherits from page
The
chapter
object is identical to the
built-in Jekyll
page
object with the same
id.
|
|
---|---|
page.id | /variables |
chapter.id | /contents |
chapter.title | Table of Contents |
chapter.slug | contents |
chapter.url | /contents.html |
... | See page documentation |
Chapter metadata | |
chapter_is_draft | false |
chapter_is_visible | true |
chapter_is_part_index | false |
chapter_sort_index | 020 |
chapter_sort_index_ext | |
Part metadata | |
part_label | |
part_unnumbered | true |
part_is_draft | false |
part_folder | 000-front |
part_sort_index | 000 |
part_sort_index_ext | |
part_index_chapter.url | |
Numbering | |
chapter_num | |
part_num |
This file is located at: _chapters/010-repo-setup/060-variables.md