It’s pretty straightforward to take that metadata and display a map with a marker in each .md file using a shortcode.
But, what I’m trying to do is to display all the markers from all the organizations in one map in my index file. Is there a way to loop over the name and location attributes in all the .md files to use them as markers in my map?
Everything I have found in my combing the Internet only displays one marker, and I can’t find a way to loop over these attributes in frontmatter and pass them to a partial.
Then call the partial and render however you want. For example, to create a unordered list:
{{ with partial "get-locations.html" . }}
<ul>
{{ range . }}
<li>{{ .title }} ({{ .location.latitude }}, {{ .location.longitude }})</li>
{{ end }}
</ul>
{{ end }}
Working example:
git clone --single-branch -b hugo-forum-topic-52491 https://github.com/jmooring/hugo-testing hugo-forum-topic-52491
cd hugo-forum-topic-52491
hugo server
This is brilliant, and a much more detailed response than what I was expecting. Thank you.
The last remaining piece of the puzzle for me is how to pass that data structure to the partial that creates my map.
The alternative is to call get-locations.html from within my partial that generates the map, instead of passing down the json array as an argument to the partial. Which should work, even though it’s not as neatly separated as I would have liked.