[SOLVED] How to retrieve list elements from YAML array front-matter?


#1

Hi,

This is my front-matter:

details:
  languages:
    - "english"
    - "russian"
    - "french"
    - "german"
  mirrors:
    - sourcename: "Southquarter"
      url: "http://www.southquarter.com/downloads/2017/DCE_v1.zip"
    - sourcename: "Google Drive"
      url: "https://drive.google.com/open?id=0B-Pj_6KRB3Lhdks0bjFURVdjMTg"
    - sourcename: "Derfy"
      url: "http://fms.derfy.net/DCE_v1.zip"
    - sourcename: "Thiefmissions"
      url: "http://thiefmissions.com/m/DeathsColdEmbrace"
    - sourcename: "Taffers Paradise"
      url: "http://www.taffersparadise.co.uk/thief2mission/DCE_v1.zip"

So, how could I retrieve this in my single.html file? What’s the function I have to use in order to render them?

Obviously, {{ .Params.details.languages }} doesn’t work alone…


#2

Well, I just solved myself…

{{ range .Params.details.languages }}
  {{ . }}
{{ end }}

{{ range .Params.details.mirrors }}
  {{ .sourcename }}
  {{ .url }}
{{ end }}

Thanks :slight_smile:

Ref. https://gohugo.io/templates/introduction/#example-1-using-context