hugo-fresh
hugo-fresh copied to clipboard
How to create list page templates with this theme?
I want to create a page that lists all pages in each content directory (eg. all blog posts).
-
I create a list.html file in themes/hugo-fresh/layouts/_default
-
I include the markup code:
{{.Content}}
{{ range .Pages }}
{{.Title}}
{{.URL}}
- In the directory (eg. content/blog/) I create a _index.md file.
Unfortunately this generates a Hugo server error.
Rebuild failed:
"/Users/home/Library/Mobile Documents/com~apple~CloudDocs/codebase/create/hugo/dating-app-website/hugo-website-fresh-theme/themes/hugo-fresh/layouts/partials/single/content.html:19:1": parse failed: template: partials/single/content.html:19: unexpected EOF
17 18 | </div> </section>
-- | --
I notice the config.yaml file includes these lines:
disableKinds:
- taxonomy
- taxonomyTerm
Reference: https://gohugo.io/templates/lists/
Update: list.html successfully renders content in _index.html, however, list templates seem to not function as per the Hugo documentation.
I noticed that I will get the list if I have
<h1>{{ .Title }}</h1>
{{ range .Pages }}
<li>
<a href="{{.Permalink}}">{{.Date.Format "2006-01-02"}} | {{.Title}}</a>
</li>
{{ end }}
in themes/hugo-fresh/layouts/_default/list.html
but the list will disappear when I use
{{ block "main" . }}
<h1>{{ .Title }}</h1>
{{ range .Pages }}
<li>
<a href="{{.Permalink}}">{{.Date.Format "2006-01-02"}} | {{.Title}}</a>
</li>
{{ end }}
{{ end }}
I noticed that I will get the list if I have
<h1>{{ .Title }}</h1> {{ range .Pages }} <li> <a href="{{.Permalink}}">{{.Date.Format "2006-01-02"}} | {{.Title}}</a> </li> {{ end }}
in
themes/hugo-fresh/layouts/_default/list.html
but the list will disappear when I use{{ block "main" . }} <h1>{{ .Title }}</h1> {{ range .Pages }} <li> <a href="{{.Permalink}}">{{.Date.Format "2006-01-02"}} | {{.Title}}</a> </li> {{ end }} {{ end }}
You need to define main, not create a block. The block already exists in the baseof template. So in list.html you do:
{{ define "main" }}
<h1>{{ .Title }}</h1>
{{ range .Pages }}
<li>
<a href="{{.Permalink}}">{{.Date.Format "2006-01-02"}} | {{.Title}}</a>
</li>
{{ end }}
{{ end }}
Sorry I'm a noob but I don't get it. Starting from single.html I created a list.html layout adding the above code.
Then created a _index.md in content/blog with the following
--- title:index sidebar: false # or false to display the sidebar sidebarlogo: fresh-white-alt # From (static/images/logo/) include_footer: true # or false to display the footer ---
but when I go to http://localhost:1313/blog/
nothing shows up
I'm getting back to the question cause I can get it to work. Any chance somebody could share a list.html code? Sorry to bother but I really like your fun and easy theme.
Dev Info for myself: https://gohugo.io/templates/lists/