Problem accessing yaml data


#1

Hi,

I have the following dates.yaml in my data folder:

de:
1: Jänner
2: Feburar
3: März
4: April
5: Mai
6: Juni
7: Juli
8: August
9: September
10: Oktober
11: November
12: Dezember
en:
1: Janurary
2: Feburary
3: March
4: April
5: May
6: June
7: July
8: August
9: September
10: October
11: November
12: December

In my template I try to access the corresponding key with {{ index $.Site.Data.dates.en (printf “%d” .Date.Month) }}. But that doesn’t seem to work. If I hardcode the month like {{ index $.Site.Data.dates.en 12 }} it works without problems. Am I doing anything wrong or missing a obligatory parsing of the date?

Thanks,
Thomas


#2

I solved this problem the following way. I added another key (map) in the date.yaml file:
map:
Janurary: 1
February: 2
March: 3
April: 4
May: 5
June: 6
July: 7
August: 8
September: 9
October: 10
November: 11
December: 12

and accessed the name as follows:

{{- $month := (index $.Site.Data.dates.map (printf “%s” .Date.Month)) -}}
{{- index $.Site.Data.dates .Site.Language.Lang $month }} {{ .Date.Format “02” }}, {{ .Date.Year }}

This seems to get around the parsing problem. Maybe this helps someone.

Best regards,
Thomas