Hugo & YML Data

Hi, I want to access Data from a “loremipsum.yml” and put it in the HTML.
I already tried everything like a div with “$.Site.Data.loremipsum”. But it is still not working. Can anyone help me?

Have you placed the file in the “data” directory? Have you looked at the documentation examples?

The file is in the Data dir.

Then the content of the file is loaded as a map that can be accessed with site.Data.loremipsum.

Something like this should output something.

{{ range site.Data.loremipsum }}
   {{ . }}
{{ end }}

Example content of the file?

That’s what it look like.

<div class="whatever">
{{ range site.Data.loremipsum }}
    {{ .title }}
{{ end }}
</div>

the yml file looks like this:

stories:
  - title: asdf
    logo: pic.svg
    logo_unpadded: true
    screenshot: lorem

I find JSON easier to read, so let’s look at your data:

<pre>{{ jsonify (dict "indent" "  ") site.Data.loremipsum }}</pre>
{
  "stories": [
    {
      "logo": "pic.svg",
      "logo_unpadded": true,
      "screenshot": "lorem",
      "title": "asdf"
    }
  ]
}

At the root, there is nothing to “range” through.

If you want to range through the array of stories:

{{ range site.Data.loremipsum.stories }}
  {{ .title }}
{{ end }}

It have to be yaml

Please read my previous message again.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.