Listing multiple different contents

I’ve searched the docs Lists of Content in Hugo | Hugo

I need to display two different types of content with completely different parameters / views
(blog, services) they both have content:

blog.md

---
title: "{{ replace .Name "-" " " | title }}"
subtitle: ""
layout: "single_blog"
---

service.md

---
title: "{{ replace .Name "-" " " | title }}"
subtitle: ""
layout: "single_service"
---

I’m handling the ‘single’ template with the layout, Is there a way to override the current list or a elegent way to list these out?

Please tell me if this is the correct way or if there’s a better way that I don’t see, I’m grabbing the url and using that to point to my content folder.

list.html:

        {{ $content := trim $url "/" }} //$url = "blog"
        {{ $paginator := .Paginate (where site.RegularPages "Section" "==" $content ) }}
        <div class="uk-grid-match uk-child-width-1-3@m uk-text-center" uk-grid>
        {{ range  $paginator.Pages }}
            <div>
              {{ .Render (printf "list_%s" $content) }}
            </div>
        {{ end }}
        </div>

No, that is not how Section lists should be rendered.

One doesn’t really need to manipulate the Permalink string to point to a specific Section.

If you want to specify different layouts for different Sections, you can use simpler methods like:

  1. Provide the relevant markup, within a condition like: if eq .Section "blog" etc, in the main list template under /layouts/_default/list.html

OR

  1. Provide a different template for each Section (see: the lookup order for Sections for information regarding the location of a list template for a specific Section).

Okay it’s a little confusing in the docs, if I understand correctly to use the lookup order of multiple different lists for content my structure looks like this?

content--|
               blog
                    first_blog.md
               service
                    my_service.md

layout
            _default
                  list.html
             blog
                  list.html
             service
                   list.html

Yes, that is correct.

1 Like

I’m also just going to guess if I put a single.html in those directories that that will be the new singles page… :man_facepalming:

Yes. If you need different single page templates for each Section, then that is the place to define them.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.