Topbar
The theme comes with a reasonably configured topbar. You can learn how to configure the defaults in this section.
Nevertheless, your requirements may differ from this configuration. Luckily, the theme has you covered as the topbar, its elements, and the functionality behind these elements are fully configurable by you.
All mentioned file names below can be clicked and show you the implementation for a better understanding.
Areas
The default configuration comes with predefined areas that may contain an arbitrary set of elements.
- start: shown between menu and breadcrumb
- middle: shown between the start and the end area, taking the remaining space; contains the breadcrumb
- end: shown on the opposite breadcrumb side in comparison to the start area
- more: shown when pressing the more button in the topbar
While you cannot add additional areas in the topbar, you are free to write additional area buttons that behave like the more button, each providing a further user-defined area with its own option.
Elements
Everything displayed in an area is an element. Most elements are buttons, but an element can display anything else.
The theme ships with the following predefined elements (from left to right in the screenshot). Each is identified by its type:
- sidebarbutton: opens the sidebar flyout if in mobile layout
- tocbutton: opens the table of contents in an overlay
- breadcrumbs: the breadcrumb of the page, or its title if the breadcrumb is disabled
- editbutton: browses to the editable page if the
editURLparameter is set - sourcebutton: shows the page’s source code if source support was activated
- markdownbutton: shows the page’s markdown source if markdown support was activated
- printbutton: browses to the chapter’s printable page if print support was activated
- prevbutton: browses to the previous page if there is one
- nextbutton: browses to the next page if there is one
- morebutton: opens the overlay for the more area
Not all elements are displayed at every given time. This is configurable (see below if interested).
Defining Topbar Elements
Option Front Matter The elements are defined for each area of the topbar:
topbarstart: the start areatopbarmiddle: the middle areatopbarend: the end areatopbarmore: the more area
As these options are arrays, you can define as many elements as you like in each area. The elements are displayed in the given order. Each element is identified by its type and may be given further parameters, depending on the element.
If you don’t set these options in your hugo.toml, the theme defaults to the following configuration. The more area is empty by default; some elements are moved there depending on the screen width.
If you want to reconfigure an area, you have to copy over every element from the default configuration you want to keep, as reconfiguration will reset all elements of that area.
Example
The following example
- removes all elements but the more button from the end area
- displays the more button even if its overlay is empty by setting its
onemptyparameter todisable - puts the print button into the more area on all screen widths
Redefining Topbar Elements for Certain Pages
Suppose you are building a site that contains a topmost log section.
When the user is on one of the log pages, the topbar should not offer to edit the page, and the print button should be tucked away in the more area. All other pages should keep the default elements.
Directory structure:
- content
- log
- first-day.md
- second-day.md
- third-day.md
- _index.md
- _index.md
- log
Option Front Matter Using Hugo’s cascade feature, we can redefine the elements once in log/_index.md setting topbarend and topbarmore so they will be used in all children pages.
Setting the topbarend Front Matter will overwrite all default elements of the end area. If you want to display the arrow navigation and the more button as well like in this example, you have to declare them with the Front Matter as given in the default options. The start area is not redefined and keeps its elements.
Defining Own Elements
Besides the predefined elements, you can write your own. Store its template in layouts/partials/topbar/element/<TYPE>.html of your site and add it with { type = '<TYPE>' } to one of the topbar areas.
Your template receives every parameter of its configuration, and additionally the displayed page as page.
The topbar manages what the button function writes: it shows, hides and moves it depending on the screen width. So use this function to display your element, even if it is not a plain button, putting what you want to show into the content of the button.
Defining Own Areas
The more area is nothing special: the more button opens it by calling the area-button function with the area name more, and the option topbarmore fills it.
You can add further areas the same way. Write your own element calling the area-button function with an area name <AREA>. Its area is filled by the option topbar<AREA>, which is configured like the options of the predefined areas and can be set in the front matter as well.
As your template is free to call Hugo’s T function, the tooltip is taken from your translation files.
Other elements can be moved into your area depending on the screen width with the area-tools action.
Button Types
The theme distinguishes between two types of buttons:
- button: a clickable button that either browses to another site, triggers a user-defined script or opens an overlay containing user-defined content
- area-button: the template for the more button, to define your own area overlay buttons
Element Parameters
Screen Widths and Actions
Depending on the screen width, you can configure how a button should behave. This applies to every element written by the button or area-button function, but not to other elements like the breadcrumbs, which always stay in their area. Screen width is divided into three classes:
- s: (controlled by the
onwidthsparameter) small (mobile) layout where the menu sidebar is hidden - m: (controlled by the
onwidthmparameter) medium desktop layout with visible sidebar while the content area width still resizes - l: (controlled by the
onwidthlparameter) large desktop layout with visible sidebar once the content area reached its maximum width
For each width class, you can configure one of the following actions:
show: the button is displayed in its given areahide: the button is removedarea-XXX: the button is moved from its given area into the areaXXX; for example, this is used to move buttons to the more area overlay in the mobile layout
Hiding and Disabling Stuff
While hiding an element depending on the screen size can be configured with the above-described hide action, you may want to hide the element on certain other conditions as well.
For example, the print button in its default configuration should only be displayed if print support was configured. This is done in your element template by checking the conditions first before displaying the element (see layouts/partials/topbar/element/printbutton.html).
Another preferred condition for hiding a button is if the displayed overlay is empty. This is the case for the toc (see layouts/partials/topbar/element/tocbutton.html) as well as the more button and controlled by the parameter onempty.
This parameter can have one of the following values:
disable: the button is displayed in a disabled state if the overlay is emptyhide: the button is removed if the overlay is empty
If you want to disable a button containing no overlay, this can be achieved by an empty href parameter. An example can be seen in the prev button (see layouts/partials/topbar/element/prevbutton.html) where the URL for the previous site may be empty.
Reference
Predefined Elements
The predefined button elements by the theme (all predefined elements besides the breadcrumbs, tocbutton and morebutton). The breadcrumbs element has no parameters besides its type.
The <varying> parameter values are different for each element and configured for standard behavior as seen on this page.
| Name | Default | Notes |
|---|---|---|
| type | <empty> | Mandatory type of the element. |
| onwidths | <varying> | The action that should be executed if the site is displayed in the given width: - show: The element is displayed in its given area- hide: The element is removed.- area-XXX: The element is moved from its given area into the area XXX. |
| onwidthm | <varying> | See above. |
| onwidthl | <varying> | See above. |
Predefined Overlay Elements
The predefined elements by the theme that open an overlay (the tocbutton and morebutton).
The <varying> parameter values are different for each element and configured for standard behavior as seen on this page.
| Name | Default | Notes |
|---|---|---|
| type | <empty> | Mandatory type of the element. |
| onempty | hide |
Defines what to do with the button if the content overlay is empty: - disable: The button is displayed in a disabled state.- hide: The button is removed. |
| onwidths | <varying> | The action that should be executed if the site is displayed in the given width: - show: The element is displayed in its given area- hide: The element is removed.- area-XXX: The element is moved from its given area into the area XXX. |
| onwidthm | <varying> | See above. |
| onwidthl | <varying> | See above. |
Button
Contains the basic button functionality and is used as a base implementation for all predefined button elements (layouts/partials/topbar/func/button.html).
Call this from your own element templates if you want to implement a button without an overlay like the print button (layouts/partials/topbar/element/printbutton.html) or with an overlay containing arbitrary content like the toc button (layouts/partials/topbar/element/tocbutton.html).
For displaying an area in the button’s overlay, see Area-Button.
Parameters
| Name | Default | Notes |
|---|---|---|
| page | <empty> | Mandatory reference to the page. |
| class | <empty> | Mandatory unique class name for this button. Displaying two buttons with the same value for class is undefined. |
| href | <empty> | Either the destination URL for the button or JavaScript code to be executed on click. - If starting with javascript: all following text will be executed in your browser- Every other string will be interpreted as URL - If empty and no action is set, the button will be displayed in a disabled state regardless of its content |
| action | <empty> | Name of the action to execute on click, handled by a script instead of inline JavaScript, so it works with a strict Content Security Policy. If set, href is not needed. - toggle-flyout: shows or hides the content overlay- toggle-nav: shows or hides the sidebar menu- any other name: execute your own code, see the button shortcode |
| istoggle | false |
If true, the button announces to assistive technology that it shows and hides something. Set it if your action is toggle-flyout or toggle-nav. For your own action, see the button shortcode. |
| icon | <empty> | Font Awesome icon name. |
| onempty | disable |
Defines what to do with the button if the content parameter was set but ends up empty: - disable: The button is displayed in a disabled state.- hide: The button is removed. |
| onwidths | show |
The action that should be executed if the site is displayed in the given width: - show: The button is displayed in its given area- hide: The button is removed.- area-XXX: The button is moved from its given area into the area XXX. |
| onwidthm | show |
See above. |
| onwidthl | show |
See above. |
| hint | <empty> | Arbitrary text displayed in the tooltip. |
| title | <empty> | Arbitrary text for the button. |
| content | <empty> | Arbitrary HTML to put into the content overlay. This parameter may be empty. In this case, no overlay will be generated. |
Area-Button
Contains the basic functionality to display area overlay buttons (layouts/partials/topbar/func/area-button.html).
Call this from your own element templates if you want to implement a button with an area overlay like the more button (layouts/partials/topbar/element/morebutton.html), see Defining Own Areas.
Parameters
| Name | Default | Notes |
|---|---|---|
| page | <empty> | Mandatory reference to the page. |
| area | <empty> | Mandatory unique area name for this area. Displaying two areas with the same value for area is undefined. The area is filled by the option topbar<AREA>. |
| icon | <empty> | Font Awesome icon name. |
| onempty | disable |
Defines what to do with the button if the content overlay is empty: - disable: The button is displayed in a disabled state.- hide: The button is removed. |
| onwidths | show |
The action that should be executed if the site is displayed in the given width: - show: The button is displayed in its given area- hide: The button is removed.- area-XXX: The button is moved from its given area into the area XXX. |
| onwidthm | show |
See above. |
| onwidthl | show |
See above. |
| hint | <empty> | Arbitrary text displayed in the tooltip. |
| title | <empty> | Arbitrary text for the button. |
Migration for Relearn 9
Previously, the content of an area was defined by a template in layouts/partials/topbar/area that you had to override in your site to change it, calling button templates from layouts/partials/topbar/button. Now the areas are configured by options, the same way as the sidebar menus, listing elements stored in layouts/partials/topbar/element.
Your templates are still honored. If the theme finds an area template, it defines the area and takes precedence over the options. The theme’s button templates can still be called from it. In both cases your build will give you a deprecation warning naming the file. Start to migrate early, as this will be removed with the next major update of the theme.
Predefined Areas
If you have overridden start.html, end.html or more.html in layouts/partials/topbar/area, turn each call of a button template into an entry of the option named after the area and delete the file.
| Legacy Template | New Option |
|---|---|
layouts/partials/topbar/area/start.html |
topbarstart |
layouts/partials/topbar/area/end.html |
topbarend |
layouts/partials/topbar/area/more.html |
topbarmore |
The button template becomes the type of the entry according to the following table. Every parameter besides page is carried over unchanged.
| Legacy Template | New Type |
|---|---|
topbar/button/sidebar.html |
sidebarbutton |
topbar/button/toc.html |
tocbutton |
topbar/button/edit.html |
editbutton |
topbar/button/source.html |
sourcebutton |
topbar/button/markdown.html |
markdownbutton |
topbar/button/print.html |
printbutton |
topbar/button/prev.html |
prevbutton |
topbar/button/next.html |
nextbutton |
topbar/button/more.html |
morebutton |
For example, this template
becomes
If your template showed different buttons depending on the page, set the option in the front matter of these pages instead.
Own Buttons
Move your button templates from layouts/partials/topbar/button to layouts/partials/topbar/element. Once the area template calling them is deleted, list them in the option by their file name. The templates themselves don’t need to be changed.
An element now receives all parameters of its entry and the displayed page as page, where your button previously received what your area template passed to it.
Overridden Buttons
If you have overridden one of the theme’s button templates in layouts/partials/topbar/button, your version is only used by your own area templates. The configured elements don’t know of it.
Move it to layouts/partials/topbar/element, renaming it according to the table above.
Own Areas
If you have written your own button calling topbar/func/area-button.html together with a template layouts/partials/topbar/area/<AREA>.html for its content, move your button to layouts/partials/topbar/element like your other buttons and replace the area template by the option of its area.
For example, these templates
become the unchanged button template moved to layouts/partials/topbar/element/toolsbutton.html and

