Theme Structure and Layout#
This section describes some basic ways to control the layout and structure of your documentation. This theme inherits its structure and section terminology from the Sphinx Basic NG theme.
Overview of theme layout#
Below is a brief overview of the major layout of this theme.
Take a look at the diagram to understand what the major sections are called.
Where you can insert component templates in html_theme_options
, we include the variable name in inline code
.
Click on section titles to learn more about them and some basic layout configurations.
article_header_start
article_header_end
Article Content
article_footer_items
prev_next_area
Horizontal spacing#
By default, the theme’s three columns have fixed widths.
The primary sidebar
will snap to the left, the secondary sidebar
will snap to the right, and the article content
will be centered in between.
If one of the sidebars is not present, then the
article content
will be centered between the other sidebar and the side of the page.If neither sidebar is present, the
article content
will be in the middle of the page.
If you’d like the article content
to take up more width than its default, use the max-width
CSS property with the following selectors:
.bd-main .bd-content .bd-article-container {
max-width: 100%; /* default is 60em */
}
The above rule will set the article content max width to the same width as the top navigation bar. To truly use all of the available page width, you also need to set the following CSS rule:
.bd-page-width {
max-width: 100%; /* default is 88rem */
}
This will affect both the article content and the top navigation bar.
Note
If you use both of the custom CSS rules above, be sure to keep them as separate rules in your CSS file. If you combine them, the result will be a CSS selector that is less specific than the two default rules in the theme, and your custom CSS will fail to override the theme defaults.
Templates and components#
There are a few major theme sections that you can customize to add/remove built-in components or add your own components. Each section is configured with a list of HTML templates — these are snippets of HTML that are inserted into the section by Sphinx.
You can choose which templates show up in each section, as well as the order in which they appear. This page describes the major areas that you can customize.
Note
When configuring templates in each section, you may omit the .html
suffix after each template if you wish.
Article Header#
Located in sections/header-article.html
.
The article header is a narrow bar just above the article’s content. There are two sub-sections that can have component templates added to them:
article_header_start
is aligned to the beginning (left) of the article header. By default, this section has thebreadcrumbs.html
component which displays links to parent pages of the current page.article_header_end
is aligned to the end (right) of the article header. By default, this section is empty.
Built-in components to insert into sections#
Below is a list of built-in templates that you can insert into any section. Note that some of them may have CSS rules that assume a specific section (and will be named accordingly).
breadcrumbs.html
copyright.html
edit-this-page.html
footer-article/prev-next.html
icon-links.html
last-updated.html
navbar-icon-links.html
navbar-logo.html
navbar-nav.html
page-toc.html
searchbox.html
search-button.html
search-field.html
sidebar-ethical-ads.html
sidebar-nav-bs.html
sourcelink.html
sphinx-version.html
theme-switcher.html
version-switcher.html
indices.html
theme-version.html
Add your own HTML templates to theme sections#
If you’d like to add your own custom template to any of these sections, you could do so with the following steps:
Create an HTML file in a folder called
_templates
. For example, if you wanted to display the version of your documentation using a Jinja template, you could create a file:_templates/version.html
and put the following in it:<!-- This will display the version of the docs --> {{ version }}
Now add the file to your menu items for one of the sections above. For example:
html_theme_options = { # ... "navbar_start": ["navbar-logo", "version"], # ... }
Build date#
By default this theme does not display the build date even when Sphinx’s html_last_updated_fmt variable is set. If you want the build date displayed, the theme includes a last-updated
template that you can add to one of the page regions in your conf.py
. For example:
html_theme_options = {
"content_footer_items": ["last-updated"],
# other settings...
}
If you do specify html_last_updated_fmt
but don’t include the last-updated
template, the theme will still write the build date into a meta
tag in the HTML header, which can be inspected by viewing the page source or extracted with an HTML parser. The tag will look like:
<meta name="docbuild:last-update" content="Aug 15, 2023">
The tag’s content
attribute will follow the format specified in the html_last_updated_fmt
configuration variable.