|
| 1 | +==================================== |
| 2 | +Add/Remove items from theme sections |
| 3 | +==================================== |
| 4 | + |
| 5 | +There are a few major theme sections that you can customize to add/remove |
| 6 | +components, or add your own components. Each section is configured with a |
| 7 | +list of *html templates* - these are snippets of HTML that are inserted into |
| 8 | +the section by Sphinx. |
| 9 | + |
| 10 | +You can choose which templates show up in each section, as well as the order in |
| 11 | +which they appear. This page describes the major areas that you can customize. |
| 12 | + |
| 13 | +.. note:: |
| 14 | + |
| 15 | + When configuring templates in each section, you may omit the ``.html`` |
| 16 | + suffix after each template if you wish. |
| 17 | + |
| 18 | +The navbar items |
| 19 | +================ |
| 20 | + |
| 21 | +The navbar is at the top of the page, and is broken up into three sections. |
| 22 | +Each section is configured in ``conf.py`` with the following configuration: |
| 23 | + |
| 24 | +- Left section: ``html_theme_options['navbar_start']`` |
| 25 | +- Middle menu: ``html_theme_options['navbar_center']`` |
| 26 | +- Right section: ``html_theme_options['navbar_end']`` |
| 27 | + |
| 28 | +By default, the following configuration is used: |
| 29 | + |
| 30 | +.. code-block:: python |
| 31 | +
|
| 32 | + html_theme_options = { |
| 33 | + ... |
| 34 | + "navbar_start": ["navbar-logo"], |
| 35 | + "navbar_center": ["navbar-nav"], |
| 36 | + "navbar_end": ["navbar-icon-links"] |
| 37 | + ... |
| 38 | + } |
| 39 | +
|
| 40 | +The left sidebar |
| 41 | +================ |
| 42 | + |
| 43 | +The left sidebar is just to the left of a page's main content. |
| 44 | +Configuring it is a bit different from configuring the other sections, because |
| 45 | +configuring the sidebar is natively supported in Sphinx, via the ``html_sidebars`` |
| 46 | +configuration variable. |
| 47 | + |
| 48 | +For the left sidebar only, you can configure templates so that they only show |
| 49 | +up on certain pages. You do so via a configuration like so in ``conf.py``: |
| 50 | + |
| 51 | +.. code-block:: python |
| 52 | +
|
| 53 | + html_sidebars = { |
| 54 | + "<page_pattern>": ["list", "of", "templates"] |
| 55 | + } |
| 56 | +
|
| 57 | +Any pages that match ``<page_pattern>`` will have their respective templates |
| 58 | +inserted. You can also ``*`` to do ``glob``-style matching, and may use ``**`` |
| 59 | +to match all pages. |
| 60 | + |
| 61 | +By default, it has the following configuration: |
| 62 | + |
| 63 | +.. code-block:: python |
| 64 | +
|
| 65 | + html_sidebars = { |
| 66 | + "**": ["search-field", "sidebar-nav-bs", "sidebar-ethical-ads"] |
| 67 | + } |
| 68 | +
|
| 69 | +
|
| 70 | +The right in-page sidebar |
| 71 | +========================= |
| 72 | + |
| 73 | +The in-page sidebar is just to the right of a page's main content, and is |
| 74 | +configured in ``conf.py`` with ``html_theme_options['page_sidebar_items']``. |
| 75 | + |
| 76 | +By default, it has the following templates: |
| 77 | + |
| 78 | +.. code-block:: python |
| 79 | +
|
| 80 | + html_theme_options = { |
| 81 | + ... |
| 82 | + "page_sidebar_items": ["page-toc", "edit-this-page"], |
| 83 | + ... |
| 84 | + } |
| 85 | +
|
| 86 | +The footer |
| 87 | +========== |
| 88 | + |
| 89 | +The footer is just below a page's main content, and is configured in ``conf.py`` |
| 90 | +with ``html_theme_options['footer_items']``. |
| 91 | + |
| 92 | +By default, it has the following templates: |
| 93 | + |
| 94 | +.. code-block:: python |
| 95 | +
|
| 96 | + html_theme_options = { |
| 97 | + ... |
| 98 | + "footer_items": ["copyright", "sphinx-version"], |
| 99 | + ... |
| 100 | + } |
| 101 | +
|
| 102 | +A list of built-in templates you can insert into sections |
| 103 | +========================================================= |
| 104 | + |
| 105 | +Below is a list of build-in templates that you can insert into any section. |
| 106 | +Note that some of them may have CSS rules that assume a specific section (and |
| 107 | +will be named accordingly). |
| 108 | + |
| 109 | +- ``icon-links.html`` |
| 110 | +- ``search-field.html`` |
| 111 | +- ``copyright.html`` |
| 112 | +- ``edit-this-page.html`` |
| 113 | +- ``last-updated.html`` |
| 114 | +- ``navbar-icon-links.html`` |
| 115 | +- ``navbar-logo.html`` |
| 116 | +- ``navbar-nav.html`` |
| 117 | +- ``page-toc.html`` |
| 118 | +- ``sidebar-ethical-ads.html`` |
| 119 | +- ``sidebar-nav-bs.html`` |
| 120 | +- ``sphinx-version.html`` |
| 121 | + |
| 122 | +Add your own HTML templates to theme sections |
| 123 | +============================================= |
| 124 | + |
| 125 | +If you'd like to add your own custom template to any of these sections, you |
| 126 | +could do so with the following steps: |
| 127 | + |
| 128 | +1. Create an HTML file in a folder called ``_templates``. For example, if |
| 129 | + you wanted to display the version of your documentation using a Jinja |
| 130 | + template, you could create a file: ``_templates/version.html`` and put the |
| 131 | + following in it: |
| 132 | + |
| 133 | + .. code-block:: html |
| 134 | + |
| 135 | + <!-- This will display the version of the docs --> |
| 136 | + {{ version }} |
| 137 | + |
| 138 | +1. Now add the file to your menu items for one of the sections above. For example: |
| 139 | + |
| 140 | + .. code-block:: python |
| 141 | +
|
| 142 | + html_theme_options = { |
| 143 | + ... |
| 144 | + "navbar_start": ["navbar-logo", "version"], |
| 145 | + ... |
| 146 | + } |
0 commit comments