I have data/allies/count.yml
:
- people: "46"
organizations: "6"
Which I successfully extract to JSON with
{
"people": "{{ index .Site.Data.allies.count 0 "people" }}",
"organizations": "{{ index .Site.Data.allies.count 0 "organizations" }}"
}
or
{
{{ range .Site.Data.allies.count }}
"people": "{{ .people }}",
{{ end }}
{{ range .Site.Data.allies.count }}
"organizations": "{{ .organizations }}"
{{ end }}
}
My questions are:
- Can I get rid of the "
-
" in data/allies/count.yml
*? Then how must I adapt the index
or range
calls to acomodate the absence of "-
"?
- Can I simplify the
index
or range
calls, am I doing it the right way?
*I’d rather have:
people: "46"
organizations: "6"
If memory serves me right -as usually I do not work with YAML- hyphens indicate list items.
The answer to your question depends on the nature of the YAML. Does it contain multiple key-value pairs?
If no, then sure remove the hyphen.
If yes, then you need to keep it.
1 Like
There are two key-value pairs, people: "46"
and organizations: "6"
, so I would need to keep the hyphen I guess. Thanks @alexandros !
I just noticed I can do:
{{ .Site.Data.allies.count.people }}
{{ .Site.Data.allies.count.organizations }}
with data/allies/count.yml
:
people: "46"
organizations: "6"
That’s what I wanted
So simple…
1 Like
system
Closed
5
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.