# One List Layout For Different Section?

**URL:** <https://discourse.gohugo.io/t/one-list-layout-for-different-section/20321>\
**Category:** support\
**Created:** [August 20, 2019, 5:04am UTC](https://discourse.gohugo.io/t/one-list-layout-for-different-section/20321 "2019-08-20T05:04:55Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![BayuAngora](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bayuangora/32/26104_2.png) [@BayuAngora](https://discourse.gohugo.io/u/BayuAngora)\
**Post date:** [August 20, 2019, 5:04am UTC](https://discourse.gohugo.io/t/one-list-layout-for-different-section/20321/1 "2019-08-20T05:04:55Z")

</div>

Dear All

I have 3 section inside /content/ folder.

/content/  
| \_ /blog/ (all blog posts with \_index.md)  
| \_ /poem/ (all poem posts with \_index.md)  
| \_ /quote/ (all quote posts with \_index.md)

On the /layouts/\_default/ folder, I have list.html with content of all 3 section above.

I want \_index.md of each folder only display each of its section.

So, \_index.md inside blog folder only displaying posts from blog folder. And \_index.md inside poem folder only displaying posts from poem folder. Also \_index.md inside quote folder only displaying posts from quote folder.

How to solve this? Or I have to create different list layout for each section?

Regards

---

<div class="post-metadata">

**Author:** ![Yudy\_Ananda](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/yudy_ananda/32/5664_2.png) [@Yudy\_Ananda](https://discourse.gohugo.io/u/Yudy_Ananda)\
**Post date:** [August 20, 2019, 5:19am UTC](https://discourse.gohugo.io/t/one-list-layout-for-different-section/20321/2 "2019-08-20T05:19:50Z")

</div>

> **[Hugo's Lookup Order](https://gohugo.io/templates/lookup-order/)**
>
> Hugo searches for the layout to use for a given page in a well defined order, starting from the most specific.

You can create blog, poem and quote directory inside layouts then add `list.html` on each of content section

```auto
layouts/
      blog/list.html
      poem/list.html
      quote/list.html

```

if its done then you have to range the list according to their type, for example

```auto
{{ $paginator := .Paginate (where .Data.Pages "Type" "blog") }}
    {{ range $paginator.Pages }}
    ...

```

Semoga membantu

---

<div class="post-metadata">

**Author:** ![BayuAngora](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bayuangora/32/26104_2.png) [@BayuAngora](https://discourse.gohugo.io/u/BayuAngora)\
**Post date:** [August 20, 2019, 5:52am UTC](https://discourse.gohugo.io/t/one-list-layout-for-different-section/20321/3 "2019-08-20T05:52:32Z")

</div>

My current method is create 3 deifferent layouts (listblog.html, listpoem.html, listquote.html) inside /layouts/\_default folder. I don’t know which one is more efficient result between your suggestion or my current method?

By the way, terima kasih.

---

<div class="post-metadata">

**Author:** ![Yudy\_Ananda](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/yudy_ananda/32/5664_2.png) [@Yudy\_Ananda](https://discourse.gohugo.io/u/Yudy_Ananda)\
**Post date:** [August 20, 2019, 6:07am UTC](https://discourse.gohugo.io/t/one-list-layout-for-different-section/20321/4 "2019-08-20T06:07:52Z")

</div>

I guess its depend on your needs, but imo having different layout directory will make theme easier to manage, specialy if i have different template (single, list, custom uptout etc) for each content.

---

<div class="post-metadata">

**Author:** ![frjo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/frjo/32/18626_2.png) [@frjo](https://discourse.gohugo.io/u/frjo)\
**Post date:** [August 20, 2019, 12:20pm UTC](https://discourse.gohugo.io/t/one-list-layout-for-different-section/20321/5 "2019-08-20T12:20:34Z")

</div>

If you in `layouts/_default/list.html` have code like this:

```auto
{{ $paginator := .Paginate (.Pages) }}
{{ range $paginator.Pages }}
…
{{ end }}

```

The template will list all pages within the current section.

On the home page it will list all pages from all sections. Adding a `layouts/index.html` template allows you to have a custom view for the home page.

---

<div class="post-metadata">

**Author:** ![BayuAngora](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bayuangora/32/26104_2.png) [@BayuAngora](https://discourse.gohugo.io/u/BayuAngora)\
**Post date:** [August 20, 2019, 1:45pm UTC](https://discourse.gohugo.io/t/one-list-layout-for-different-section/20321/6 "2019-08-20T13:45:17Z")

</div>

Great to know if list.html (along with the code above) can filter section folder automatically. I will try that method. Thanks.

---

<div class="post-metadata">

**Author:** ![BayuAngora](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bayuangora/32/26104_2.png) [@BayuAngora](https://discourse.gohugo.io/u/BayuAngora)\
**Post date:** [August 21, 2019, 7:32am UTC](https://discourse.gohugo.io/t/one-list-layout-for-different-section/20321/7 "2019-08-21T07:32:58Z")

</div>

Hello, @frjo

I tried to use your code above, but there’s a failed building on Netlify.

```auto
Error: add site dependencies: load resources: loading templates: "/opt/build/repo/layouts/_default/list.html:16:1": parse failed: template: _default/list.html:16: undefined variable "$paginator"

```

I don’t know which code is wrong. So, I reverted back to the default theme code here -\>

> <https://github.com/BayuAngora/paper/blob/master/layouts/_default/list.html>

But the problem with the default code above is, the result only displaying posts from Poem section only, without displaying posts from Blog and Quote section?

[https://mypaper.netlify.com/blog/](https://mypaper.netlify.com/blog/)

Can you help me to correct my list.html above?

---

<div class="post-metadata">

**Author:** ![frjo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/frjo/32/18626_2.png) [@frjo](https://discourse.gohugo.io/u/frjo)\
**Post date:** [August 21, 2019, 9:47am UTC](https://discourse.gohugo.io/t/one-list-layout-for-different-section/20321/8 "2019-08-21T09:47:14Z")

</div>

The `layouts/_default/list.html` should be renamed/moved to `layouts/index.html`, it at least look like what you want on the home page and not on default list pages.

I would then put something like the following in a new `layouts/_default/list.html`:

```auto
{{ partial "head.html" . }}
{{ partial "header.html" . }}

<main class="main">

<h1>{{ .Title }}</h1>

{{ $paginator := .Paginate (.Pages) }}
{{ range $paginator.Pages }}
    <h2>{{ .Title }}</h2>
    <p>{{ .Summary }}</p>
{{ end }}

</main>

{{ partial "footer.html" . }}

```

Also rename `layouts/_default/post.html` back to `layouts/_default/single.html` and that will be the default template for single view.

If you want custom templates for a section you can put that in `layouts/section_name_here/single.html`.

---

<div class="post-metadata">

**Author:** ![BayuAngora](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bayuangora/32/26104_2.png) [@BayuAngora](https://discourse.gohugo.io/u/BayuAngora)\
**Post date:** [August 21, 2019, 12:20pm UTC](https://discourse.gohugo.io/t/one-list-layout-for-different-section/20321/9 "2019-08-21T12:20:49Z")

</div>

I got it. Thanks, Fredrik.
