Beny
August 12, 2016, 5:01pm
1
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
Beny
August 12, 2016, 5:18pm
3
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
bep
August 12, 2016, 5:50pm
4
What if you follow the same pattern as with my previous suggested fix?
Beny
August 12, 2016, 5:58pm
5
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
Thx bep
bep
August 12, 2016, 6:24pm
6
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.
Beny
August 12, 2016, 6:39pm
7
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
Beny
August 13, 2016, 7:24am
8
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