hugo-fresh icon indicating copy to clipboard operation
hugo-fresh copied to clipboard

How to create list page templates with this theme?

Open imawhale opened this issue 5 years ago • 6 comments

I want to create a page that lists all pages in each content directory (eg. all blog posts).

  1. I create a list.html file in themes/hugo-fresh/layouts/_default

  2. I include the markup code:

{{.Content}}
{{ range .Pages }}
{{.Title}}
{{.URL}}
  1. 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/

imawhale avatar Dec 19 '19 15:12 imawhale

Update: list.html successfully renders content in _index.html, however, list templates seem to not function as per the Hugo documentation.

imawhale avatar Dec 19 '19 15:12 imawhale

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 }}

rgaiacs avatar Jan 27 '20 20:01 rgaiacs

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 }}

todinov avatar Jun 06 '20 09:06 todinov

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

LucaMoiana avatar Feb 16 '22 10:02 LucaMoiana

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.

LucaMoiana avatar Oct 23 '22 21:10 LucaMoiana

Dev Info for myself: https://gohugo.io/templates/lists/

StefMa avatar Apr 08 '23 14:04 StefMa