footer_link_group:
group_1:
title: "name"
list:
- "google https://www.google.com"
- "Hugo https://gohugo.io/"
This configuration is in params. How to correctly output the list in the template. The list array is separated by spaces and contains the link text and link url.
I don’t want to use the menu to do it yet.
The picture below is a demonstration of the error.
The split function returns an array:
{{ range site.Params.footer_link_group.group_1.list }}
<span>key = {{ index (split . " ") 0 }}</span>
<span>key = {{ index (split . " ") 1 }}</span>
{{ end }}
Leave it to those who may be in need
The generated code and key names are not case sensitive.
footer_links:
enable: true
group:
Hugo:
- "Hugo https://gohugo.io/"
- "Docs https://gohugo.io/documentation/"
- "Community https://discourse.gohugo.io/"
Google:
- "Google https://www.google.com/"
- "Gmail https://mail.google.com/"
- "Map https://maps.google.com/"
{{- if .Site.Params.footer_links.enable }}
<div>
{{- range $title, $list := .Site.Params.footer_links.group }}
<strong>{{ $title }}</strong>
{{- range $list }}
{{- $text := index (split . " ") 0 }}
{{- $href := index (split . " ") 1 }}
<a href="{{ $href }}">{{ $text }}</a>
{{- end }}
{{- end }}
</div>
{{- end }}
<div>
<strong>google</strong>
<a href="https://www.google.com/">Google</a>
<a href="https://mail.google.com/">Gmail</a>
<a href="https://maps.google.com/">Map</a>
<strong>hugo</strong>
<a href="https://gohugo.io/">Hugo</a>
<a href="https://discourse.gohugo.io/">Community</a>
<a href="https://gohugo.io/documentation/">Docs</a>
</div>
1 Like
system
Closed
February 16, 2024, 1:12pm
4
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.