Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
imawhale opened this issue Dec 19, 2019 · 6 comments · May be fixed by #172
Open

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

imawhale opened this issue Dec 19, 2019 · 6 comments · May be fixed by #172
Labels
question Further information is requested

Comments

@imawhale
Copy link

imawhale commented Dec 19, 2019

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
Copy link
Author

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

@rgaiacs
Copy link

rgaiacs commented Jan 27, 2020

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
Copy link

todinov commented Jun 6, 2020

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

@StefMa StefMa added the question Further information is requested label Feb 12, 2021
@LucaMoiana
Copy link

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
Copy link

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
Copy link
Owner

StefMa commented Apr 8, 2023

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

@StefMa StefMa linked a pull request Apr 13, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants