I am able to access any front matter single value such as:
# An index.md
---
location:
latitude: 60.54445
longitude: 9.245
---
# I can easily use this value in layouts to create a leaflet map such as:
L.circle([{{ .Params.location.latitude }}, {{ .Params.location.longitude }}],
But it becomes very complicated for me to get my head around on how to get non singular values separately from front matter in Hugo?
# An index.md front matter created by netlify CMS widget map in GeoJSON string
---
location:
map: '{"type":"Point","coordinates":[60.54445,9.245]}'
---
# In this situation how can I get the Latitude and Longitude from the front matter to use in the layouts?
L.circle([{{ .Params.location.? }}, {{ .Params.location.? }}],
Thanks in advance for taking the time!
Dear @bep@jmooring can you please solve this or advice if it is possible to get the latitude and longitude values from the Hugo frontmatter
Well, the value of Params.location.map is simply a string, as far as Hugo is concerned. While you might be able to convert that to a Hugo data type, it’s probably a PITA. For my Leaflet maps, I rely on much simpler structures, basically
No. I do not use Netlify. And I try to keep things simple. I have the impression that you’re trying far too many things at once before you have a grasp of even the basic Hugo concepts.
{{ $location := dict }}
{{ with .Params.location.map }}
{{ $location = transform.Unmarshal . }}
{{ end }}
Now you have {{ $location.type }} and {{ $location.coordinates}} the latter being an array I believe, so: {{ index $location.coordinates 0 }} > 60.54445 {{ index $location.coordinates 1 }} > 9.245
Good point. And weird function name. I’d have expected something like JSONparse instead. So I didn’t find unmarshal, as it’s not even mentioned in the “See also” of the jsonify documentation
I’m aware of that. It still doesn’t make that a good function name, and I still think that it should be mentioned in the doc near jsonify (and there’s no tomlify nor yamlify, either… Nor a marshal)