diff options
Diffstat (limited to 'layouts/partials/navmenu.html')
| -rw-r--r-- | layouts/partials/navmenu.html | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/layouts/partials/navmenu.html b/layouts/partials/navmenu.html new file mode 100644 index 0000000..05fd64f --- /dev/null +++ b/layouts/partials/navmenu.html @@ -0,0 +1,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 }} + |
