StefMa / hugo-fresh

Hugo Fresh Theme
https://hugo-fresh.vercel.app
MIT License
609 stars 359 forks source link

How to create list page templates with this theme? #103

Open imawhale opened 4 years ago

imawhale commented 4 years ago

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}}
  3. 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 commented 4 years ago

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

rgaiacs commented 4 years ago

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 }}
todinov commented 4 years ago

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 }}
LucaMoiana commented 2 years ago

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 commented 1 year ago

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.

StefMa commented 1 year ago

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