Where to Discuss?

Local Group

Preface

Step Three: Icon set choice for bootstrap sidebar.

We need to prepare sidebar for use with dashboard.

Bootstrap5: Qutebrowser: Sidebar: Bootstrap Icons

To gain a more comprehensive understanding of this article, we suggest reading the previous article first.


1: Chapter Overview

Consider examine the directory structure.

Source Code: Step-03

Source code for this chapter can be obtained here:

Plain HTML

Compiled HTML Document

The static files generated by the Nunjucks templates is shown as below:

❯ ls *.html
031-navbar-awesome.html  034-navbar-ibs-svg.html
032-navbar-ibs-css.html  036-sidebar-awesome.html
033-navbar-ibs-cdn.html  037-sidebar-ibs-svg.html

Bootstrap5: Directory Structure: Compiled

Templates

Nunjucks

We have only three common templates:

  • Base Layout, and
  • Meta Head

Layout

Reusable Parent Template

The same with navbar. I group both in one chapter.

<!DOCTYPE html>
<html>

<head>
  {% block htmlhead %}
  {% endblock %}
</head>

<body>
  {% block navbar %}
  {% endblock %}

  {% block sidebar %}
  {% endblock %}
</body>

</html>

Bootstrap5: Nunjucks: Base Layout: Parent Template

Meta

Nothing special here. Just another mission impossible quote.

  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,
    initial-scale=1, shrink-to-fit=no">
  <title>Should you decide to accept.</title>

Bootstrap5: Nunjucks: Heads: Meta


2: Sidebar: Font Awesome

This FontAwesome is still the most popular Icons. So I decide to give it a try for sidebar.

Using Icon Set

Using FontAwesome is as simple as this below:

<span class="fa fa-home"></span>

For a real world example, you can examine this section below.

Assets

CSS, JS, Images

I add sidebars.css.

I also add sidebars.js which useful for tooltip. This type of sidebar does not need this tooltip.

assets
├── css
│   ├── bootstrap.css
│   └── sidebars.css
├── images
│   └── logo-gear.png
└── js
    ├── bootstrap.min.js
    ├── popper.min.js
    └── sidebars.js

Stylesheet

The sidebar.css stylesheet comes from official site. I copy this stylesheet for this example.

Templates

Nunjucks

This is all templates required, to build a HTML page example.

views
├── 036-sidebar-awesome.njk
├── heads
│   ├── 030-meta.njk
│   └── 036-sidebar.njk
├── layouts
│   └── base.njk
└── shared
    ├── 036-sidebar-collapsible.njk
    └── 036-sidebar.njk

Blocks

Nunjucks Document Source

We can fill each block with suitale chunck.

{% extends './layouts/base.njk' %}

{% block htmlhead %}
  {% include './heads/030-meta.njk' %}
  {% include './heads/031-links.njk' %}
  {% include './heads/036-sidebar.njk' %}
{% endblock %}

{% block sidebar %}
  {% include './shared/036-sidebar.njk' %}
{% endblock %}

Bootstrap5: Nunjucks: Blocks: Sidebar: FontAwesome

HTML Head

Assets: Resource Links

We only need to ad this CSS file.

  <link rel="stylesheet" type="text/css"
    href="assets/css/sidebars.css">

Bootstrap5: Nunjucks: Heads: Links

Since this code is long, I collapse the middle tag.

  <nav class="d-flex flex-nowrap">
  <div class="d-flex flex-column flex-shrink-0 p-3 bg-light"
       style="width: 280px;">
    <a href="#"
       class="d-flex align-items-center pb-3 mb-3
         link-dark text-decoration-none border-bottom">
         <img src="assets/images/logo-gear.png"
           alt="Home" width="32" height="32"/>
      &nbsp;
      <span class="fs-5 fw-semibold">Collapsible</span>
    </a>
    ...
  </div>
  </nav>

Bootstrap5: Nunjucks: Blocks: Sidebar

And show them here.

    <ul class="nav nav-pills flex-column mb-auto">
      <li class="nav-item">
        <a href="#"
            class="nav-link active"
            aria-current="page">
          <span class="fa fa-home"></span>&nbsp;
          Blog <span class="visually-hidden"
            >(current)</span>
        </a>
      </li>

      {% include './036-sidebar-collapsible.njk' %}

      <li class="border-top my-3"></li>
      <li class="nav-item">
        <a href="#" class="nav-link link-dark">
          <span class="fas fa-child"></span>
          &nbsp;About
        </a>
      </li>
    </ul>

Bootstrap5: Nunjucks: Blocks: Sidebar

We have include here for collapsible element.

I collapse the middle text.

<li class="nav-item">
  <a href="#" class="nav-link link-dark">
    <span class="fa fa-link"></span>&nbsp;Archives
    <button
      class="btn btn-toggle d-inline-flex
        align-items-center rounded border-0 collapsed"
      data-bs-toggle="collapse"
      data-bs-target="#home-collapse"
      aria-expanded="true">
    </button>
  </a>
  <div class="collapse show" id="home-collapse">
    ...
  </div>
</li>

Bootstrap5: Nunjucks: Blocks: Sidebar

And the inner element can be shown here:

    <ul class="btn-toggle-nav list-unstyled
        fw-normal pb-1 small">
      <li><a href="#"
          class="link-dark d-inline-flex
              text-decoration-none rounded">
        <span class="fa fa-tags"></span>
        &nbsp;By Tags</a></li>
      <li><a href="#"
          class="link-dark d-inline-flex
              text-decoration-none rounded">
        <span class="fa fa-folder"></span>
        &nbsp;By Category</a></li>
      <li><a href="#"
          class="link-dark d-inline-flex
              text-decoration-none rounded">
        <span class="fa fa-calendar"></span>
        &nbsp;By Chronology</a></li>
    </ul>

Bootstrap5: Nunjucks: Blocks: Sidebar

Browser Preview

Screenshot

The result can be displayed in web browser.

Bootstrap5: Qutebrowser: Sidebar: FontAwesome

Static Page

HTML Document Target


3: Sidebar: Bootstrap Icons: SVG

Using Icon Set

Using Bootstrap Icon with inline SVG symbol is, as simple as this below:

<svg class="bi pe-none me-2" width="16" height="16">
  <use xlink:href="#house-door-fill"/></svg>

For a real world example, you can examine this section below.

Assets

CSS, JS, Images, SVGs

assets
├── css
│   └── bootstrap.css
├── images
│   └── logo-gear.png
└── js
    ├── bootstrap.min.js
    ├── popper.min.js
    └── sidebars.js

SVG Symbol

  <svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
    <symbol id="home" viewBox="0 0 16 16">
      <path d="M8.354 1.146a.5.5 0 0 0-.708 0l-6 6A.5.5 0 0 0 1.5 7.5v7a.5.5 0 0 0 .5.5h4.5a.5.5 0 0 0 .5-.5v-4h2v4a.5.5 0 0 0 .5.5H14a.5.5 0 0 0 .5-.5v-7a.5.5 0 0 0-.146-.354L13 5.793V2.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1.293L8.354 1.146zM2.5 14V7.707l5.5-5.5 5.5 5.5V14H10v-4a.5.5 0 0 0-.5-.5h-3a.5.5 0 0 0-.5.5v4H2.5z"/>
    </symbol>
    <symbol id="house-door-fill" viewBox="0 0 16 16">
      <path d="M6.5 14.5v-3.505c0-.245.25-.495.5-.495h2c.25 0 .5.25.5.5v3.5a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5v-7a.5.5 0 0 0-.146-.354L13 5.793V2.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1.293L8.354 1.146a.5.5 0 0 0-.708 0l-6 6A.5.5 0 0 0 1.5 7.5v7a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5Z"/>
    </symbol>
    <symbol id="person-fill" viewBox="0 0 16 16">
      <path d="M3 14s-1 0-1-1 1-4 6-4 6 3 6 4-1 1-1 1H3Zm5-6a3 3 0 1 0 0-6 3 3 0 0 0 0 6Z"/>
    </symbol>
    <symbol id="archive-fill" viewBox="0 0 16 16">
      <path d="M12.643 15C13.979 15 15 13.845 15 12.5V5H1v7.5C1 13.845 2.021 15 3.357 15h9.286zM5.5 7h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1 0-1zM.8 1a.8.8 0 0 0-.8.8V3a.8.8 0 0 0 .8.8h14.4A.8.8 0 0 0 16 3V1.8a.8.8 0 0 0-.8-.8H.8z"/>
    </symbol>
    <symbol id="tag-fill" viewBox="0 0 16 16">
      <path d="M2 1a1 1 0 0 0-1 1v4.586a1 1 0 0 0 .293.707l7 7a1 1 0 0 0 1.414 0l4.586-4.586a1 1 0 0 0 0-1.414l-7-7A1 1 0 0 0 6.586 1H2zm4 3.5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0z"/>
    </symbol>
    <symbol id="folder-fill" viewBox="0 0 16 16">
      <path d="M9.828 3h3.982a2 2 0 0 1 1.992 2.181l-.637 7A2 2 0 0 1 13.174 14H2.825a2 2 0 0 1-1.991-1.819l-.637-7a1.99 1.99 0 0 1 .342-1.31L.5 3a2 2 0 0 1 2-2h3.672a2 2 0 0 1 1.414.586l.828.828A2 2 0 0 0 9.828 3zm-8.322.12C1.72 3.042 1.95 3 2.19 3h5.396l-.707-.707A1 1 0 0 0 6.172 2H2.5a1 1 0 0 0-1 .981l.006.139z"/>
    </symbol>
    <symbol id="calendar2-day-fill" viewBox="0 0 16 16">
      <path d="M3.5 0a.5.5 0 0 1 .5.5V1h8V.5a.5.5 0 0 1 1 0V1h1a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V3a2 2 0 0 1 2-2h1V.5a.5.5 0 0 1 .5-.5zm9.954 3H2.545c-.3 0-.545.224-.545.5v1c0 .276.244.5.545.5h10.91c.3 0 .545-.224.545-.5v-1c0-.276-.244-.5-.546-.5zm-2.24 4.855a.428.428 0 1 0 0-.855.426.426 0 0 0-.429.43c0 .238.192.425.43.425zm.337.563h-.672v4.105h.672V8.418zm-6.867 4.105v-2.3h2.261v-.61H4.684V7.801h2.464v-.61H4v5.332h.684zm3.296 0h.676V9.98c0-.554.227-1.007.953-1.007.125 0 .258.004.329.015v-.613a1.806 1.806 0 0 0-.254-.02c-.582 0-.891.32-1.012.567h-.02v-.504H7.98v4.105z"/>
    </symbol>
    <symbol id="chevron-right" viewBox="0 0 16 16">
      <path fill-rule="evenodd" d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z"/>
    </symbol>
  </svg>

Bootstrap5: Nunjucks: Blocks: SVG Symbols

Templates

Nunjucks

This is the templates we need, to generate HTML static page for this example.

views
├── 037-sidebar-ibs-svg.njk
├── heads
│   ├── 030-meta.njk
│   └── 036-sidebar.njk
├── layouts
│   └── base.njk
└── shared
    ├── 037-sidebar-collapsible.njk
    └── 037-sidebar.njk

Blocks

Nunjucks Document Source

And each block can be defined as below:

{% extends './layouts/base.njk' %}

{% block htmlhead %}
  {% include './heads/030-meta.njk' %}
  {% include './heads/033-links.njk' %}
  {% include './heads/036-sidebar.njk' %}
{% endblock %}

{% block sidebar %}
  {% include './shared/034-symbols.njk' %}
  {% include './shared/037-sidebar.njk' %}
{% endblock %}

Bootstrap5: Nunjucks: Blocks: Sidebar: Bootstrap Icons: SVG

HTML Head

Assets: Resource Links

I also add style for SVG icons.

<style>
  .bi {
    vertical-align: -.125em;
    fill: currentColor;
  }
</style>

  <link rel="stylesheet" type="text/css"
    href="assets/css/sidebars.css">

Bootstrap5: Nunjucks: Heads: Links

Since this code is long, I collapse the middle tag.

  <nav class="d-flex flex-nowrap">
  <div class="d-flex flex-column flex-shrink-0 p-3 bg-light"
       style="width: 280px;">
    <a href="#"
       class="d-flex align-items-center pb-3 mb-3
         link-dark text-decoration-none border-bottom">
         <img src="assets/images/logo-gear.png"
           alt="Home" width="32" height="32"/>
      &nbsp;
      <span class="fs-5 fw-semibold">Collapsible</span>
    </a>
    <ul class="nav nav-pills flex-column mb-auto">
      ...
    </ul>
  </div>
  </nav>

Bootstrap5: Nunjucks: Blocks: Sidebar

And show them here.

      <li class="nav-item">
        <a href="#"
            class="nav-link active"
            aria-current="page">
          <svg class="bi pe-none me-2" width="16" height="16"
            ><use xlink:href="#house-door-fill"/></svg>
          Blog <span class="visually-hidden"
            >(current)</span>
        </a>
      </li>

      {% include './037-sidebar-collapsible.njk' %}

      <li class="border-top my-3"></li>
      <li class="nav-item">
        <a href="#" class="nav-link link-dark">
          <svg class="bi pe-none me-2" width="16" height="16"
            ><use xlink:href="#person-fill"/></svg>
          About
        </a>
      </li>

Bootstrap5: Nunjucks: Blocks: Sidebar

We have include here for collapsible element.

I collapse the middle text.

<li class="nav-item">
  <a href="#" class="nav-link link-dark">
    <svg class="bi pe-none me-2"
         width="16" height="16"
      ><use xlink:href="#archive-fill"/></svg>
    Archives
    <button
      class="btn btn-toggle d-inline-flex
        align-items-center rounded border-0 collapsed"
      data-bs-toggle="collapse"
      data-bs-target="#home-collapse"
      aria-expanded="true">
    </button>
  </a>
  <div class="collapse show" id="home-collapse">
    ...
  </div>
</li>

Bootstrap5: Nunjucks: Blocks: Sidebar

And the inner element can be shown here:

    <ul class="btn-toggle-nav list-unstyled
        fw-normal pb-1 small">
      <li><a href="#"
          class="link-dark d-inline-flex
              text-decoration-none rounded">
        <svg class="bi pe-none me-2"
             width="16" height="16"
          ><use xlink:href="#tag-fill"/></svg>
        By Tags</a></li>
      <li><a href="#"
          class="link-dark d-inline-flex
              text-decoration-none rounded">
        <svg class="bi pe-none me-2"
             width="16" height="16"
          ><use xlink:href="#folder-fill"/></svg>
        By Category</a></li>
      <li><a href="#"
          class="link-dark d-inline-flex
              text-decoration-none rounded">
        <svg class="bi pe-none me-2"
             width="16" height="16"
          ><use xlink:href="#calendar2-day-fill"/></svg>
        By Chronology</a></li>
    </ul>

Bootstrap5: Nunjucks: Blocks: Sidebar

Browser Preview

Screenshot

Bootstrap5: Qutebrowser: Sidebar: Bootstrap Icons

Static Page

HTML Document Target

I think that’s all with sidebar.


What is Next 🤔?

Enough with template and navbar. We are going to explore the power of bootstap, by customizing its very stylesheet.

Consider continue reading [ Bootstrap - Sass - Introduction ].