LoginSignup
3
1

More than 3 years have passed since last update.

Hugo でパンくずリストを表示してみた

Posted at

Hugo でパンくずリストを表示してみたので、メモ。https://maku77.github.io/hugo/template/breadcrumbs.html を参考にしています。

パンくずリストのコード

layout/partials/breadcrumb.html に、以下のように書きます。

{{- define "breadcrumb" }}
    {{- if .node.Parent }}
        {{- template "breadcrumb" (dict "node" .node.Parent "start" .start) }}
    {{- else if not .node.IsHome }}
        {{- template "breadcrumb" (dict "node" .node.Site.Home "start" .start) }}
    {{- end }}

    {{- if eq .node .start }}
<li class="breadcrumb-item active" aria-current="page">{{ .node.LinkTitle }}</li>
    {{- else }}
<li class="breadcrumb-item"><a href="{{ .node.Permalink }}">{{ .node.LinkTitle }}</a></li>
    {{- end }}
{{- end }}

表示したい箇所で、以下のように書きます。

<nav aria-label="breadcrumb">
  <ol class="breadcrumb">
    {{- template "breadcrumb" (dict "node" . "start" .) }}
  </ol>
</nav>

スタイル設定

スタイル設定は、bootstrap4系の装飾をそのまま使っています。 詳しくは https://getbootstrap.com/docs/4.0/components/breadcrumb/ 参照。

実際の活用例

自動計算サイトで試しました。https://calculator.jp/science/chi-squared/ をごらんください。

パンくずリストを表示

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1