[solved] .Page.Params and image - wrong context?

Hi All,

Atm I am struggeling with the context, i guess.

This snippet is in a partial. I wannt to iterate over the pages and display only the Image defined in the frontmatter of the first page.

{{ range (first 1 (where .Data.Pages "Section" "post")) }}
  <img src='{{ $.Site.BaseURL }}/images/{{ .Page.Params.image }}'/>
  {{ .Page.Summary }}
{{ end }}

The {{ .Page.Summary }} works well.
But i get this error because of the image:

.Page.Params.image>: Page is not a field of struct type *hugolib.Page

Thx for help

{ .Params.image }}

Hi bep,

thx for your help. The image displays well.

But now {{ .Page.Summary }} and {{ .Page.Title }} causing errors.

Page is not a field of struct type *hugolib.Page

What if you follow the same pattern as with my previous suggested fix?

I tried and it works for the images.
I get the summary with
{{ .Summary }}
which is fine.

The last thing is the Title as link
<a href="{{ .Page.Permalink }}">{{ .Page.Title }}</a>

I get the error again.

Context in Go is kind of a rocket Science :wink:

Thx bep

It isn’t really. But instead of walking you through each use of a page variable, I suggest you head over to the documentation site and read it until you understand the base concepts.

I did it - a couple of times.
The documentation is not easy to understand for a beginner when it comes to the context.

Thx i will find out the rest.

1 Like

In case someone is looking for the solution with “Title” - Here it is

<h3><a href="{{ .Permalink }}">{{ .Title }}</a></h3>

That works for me.
I had to remove the context “Page” from the Permalink too.

{{ range (first 1 (where .Data.Pages "Section" "post" )) }}
        <img class="featurepic" src='{{ $.Site.BaseURL }}/images/{{ .Params.image }}'/>
        <h3><a href="{{ .Permalink }}">{{ .Title }}</a></h3>
        {{ .Summary }}
{{ end }}
1 Like