Access self-defined meta data in overview page

Hi,

At the moment I render a overview page of all my blog posts with following code:

          {{ range .Data.Pages.ByPublishDate }}
            <div class="row">
              <div class="col-sm-4 col-md-4 col-lg-4">
                <h5 style="text-align: right">
                  {{ .Date.Format "January 2, 2006" }}
                </h5>
               </div>
               <div class="col-sm-8 col-md-8 col-lg-8">
                 <h5 style="text-align: left">
                  <strong><a href="{{ .RelPermalink }}">{{ .Title | markdownify }}</a></strong>
                </h5>
              </div>
            </div>
          {{ end }}
        {{ end }}

Now I would like to extend it to show additional meta data, defined at the header of my blog posts. For example each blog post has a field “image” which contains a URL to a header image. I would like to show this on the overview page. But if I do something like:

          {{ range .Data.Pages.ByPublishDate }}
            <img src="{{ .Image }}">
          {{ end }}

I get this error message:

ERROR 2018/01/08 21:26:39 Error while rendering “taxonomy”: template: theme/_default/list.html:30:29: executing “theme/_default/list.html” at <.Image>: can’t evaluate field Image in type *hugolib.Page

It seems that only some pre-defined variables are accessible like “.Title” or “.Date” but how do I access other, self-defined variables from the meta data area of my blog posts?

There is no such Hugo variable. If it is an img Front Matter parameter you are calling, then the syntax should be:

{{ with .Params.image }}<img src="{{ . }}">{{ end }}

1 Like

Thanks, “.Params.image” was exactly what I was looking for! :smiley: