summaryrefslogtreecommitdiff
path: root/layouts/partials/navmenu.html
blob: 05fd64f8fddd32082b726f5fe1ac6e31f8589729 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
{{- /*
Renders a menu for the given menu ID.

@context {page} page The current page.
@context {string} menuID The menu ID.

@example: {{ partial "navmenu.html" (dict "menuID" "main" "page" .) }}
*/}}

{{- $page := .page }}
{{- $menuID := .menuID }}

{{- with index site.Menus $menuID }}
    <nav role="navigation" aria-label="{{ i18n "mainNavigation" | default "Main navigation" }}">
        <ul>
            {{ range . }}
                {{- $attrs := dict "href" .URL }}
                {{- if $page.IsMenuCurrent .Menu . }}
                    {{- $attrs = merge $attrs (dict "class" "active" "aria-current" "page") }}
                {{- else if $page.HasMenuCurrent .Menu .}}
                    {{- $attrs = merge $attrs (dict "class" "ancestor" "aria-current" "true") }}
                {{- end }}
            {{- $name := .Name }}
            <!-- Translations -->
            {{- with .Identifier }}
                {{- with T . }}
                    {{- $name = . }}
                {{- end }}
            {{- end }}
            <li>
                <a
                    {{- range $k, $v := $attrs }}
                        {{- with $v }}
                            {{- printf " %s=%q" $k $v | safeHTMLAttr }}
                        {{- end }}
                    {{- end -}}
                >
                    {{ $name }}
                </a>
            </li>
            {{- end }}
        </ul>
    </nav>
{{- end }}