Adding Navigation Buttons
User Guide → Adding Navigation ButtonsNavigation buttons can greatly help your website visitors browse through your content with ease.
Overview of steps
In the following example, we will be editing the site content generated from the default template (by running markbind init
in the terminal).
njk
in the root directory.common.njk
with the following code:{% macro previous_next(previous_page, next_page) %}
<div class="clearfix">
{% if previous_page != ''%}
<span class="float-start">
<a class="btn btn-light" href="{{ previous_page }}.html">
<md>:far-arrow-alt-circle-left: <include src="{{ previous_page }}.md#title" inline />
</md>
</a>
</span>
{% endif %}
{% if next_page != ''%}
<span class="float-end">
<a class="btn btn-light" href="{{ next_page }}.html">
<md>
<include src="{{ next_page }}.md#title" inline /> :far-arrow-alt-circle-right:
</md>
</a>
</span>
{% endif %}
</div>
<br>
{% endmacro %}
Example Here is an example of how the default template's directory structure will look like after the changes.
topic1.md
file:<!--- Add this to the top of the file -->
<span id="title" class="d-none">Topic 1</span>
<!--- Add this to the end of the file -->
{% from "njk/common.njk" import previous_next %}
{{ previous_next('', 'topic2') }}
topic2.md
file:<!--- Add this to the top of the file -->
<span id="title" class="d-none">Topic 2</span>
<!--- Add this to the end of the file -->
{% from "njk/common.njk" import previous_next %}
{{ previous_next('topic1', '') }}
Example Here is an example of how the files will look like after the changes.
<span id="title" class="d-none">Topic 1</span>
<br>
# Topic 1
> More content to be added
{% from "njk/common.njk" import previous_next %}
{{ previous_next('', 'topic2') }}
<span id="title" class="d-none">Topic 2</span>
<br>
<box>
<span class="fas fa-tools"></span><span> This is a placeholder page</span>
</box>
{% from "njk/common.njk" import previous_next %}
{{ previous_next('topic1', '') }}
You should now be able to navigate between Topic 1
and Topic 2
with ease!
Whenever you create a new page, be sure to include the following code below and replace the parts enclosed in the square brackets e.g [Name_Of_Section]
.
<!--- Creates an invisible title used in the common.njk file -->
<span id="title" class="d-none">[Name_Of_Section]</span>
{% from "njk/common.njk" import previous_next %}
{{ previous_next('[Previous_Page_Filename]', '[Next_Page_Filename]') }}