Embedding a list page into index.html without duplicating the template

I have an index.html page so I can have a custom homepage. I also have a /posts URL, which is a list page created by Hugo.

What I want is to add the content of list.html applied to /posts into index.html, so I get a list of posts on my homepage. I don’t want some naive HTML embed of /posts because that would include the header and footer for example, which are defined in baseof.html.

I just want to somehow “include” list.html but telling it to render itself as if it were for the /posts page.

Right now, I just naively copy the contents of the list template into the homepage, which I don’t feel good about.

You can insert something like this into your home page template:

{{ range where site.RegularPages "Section" "posts" }}
  <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}

Ah, I was thinking that somehow embedding a render of the list page for /posts would have been shorter and more DRY code, but I think that was a very convoluted solution in comparison to this. Thank you!

1 Like

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