Create an home page whose content comes from "partial" file stored in the content folder

Hello there,
I’m fairly new to Hugo and I was wondering whether the following scenario is manageable with this platform.

I have my home page, which need 5 blocks, but each of them represents a piece of content that should be editable in a simple way.
Can I write a function and pass some arguments, one of these the path to an .md file in a content folder to be included (once processed)?


Yes, it’s possible. There’s at least a couple of ways to do it, but it’s probably best if you put these things in their own section (content/front/front*.md). If you can iterate over the 5 blocks of content, then create your homepage to iterate over only the content from that section (I do that for my blog section).

If you can’t iterate over that section, I would still put the content in its own section, but you will have to use range to select each content section.

I would make sure that the front section has empty list.html and single.html implementations—that way they can’t be shown on their own; they will still show up in the sitemap and RSS feeds, though, so you may need to make sure that you modify the default feed formats.

Hi @halostatue

thanks for the advice.
Surely I will separate my HP content to make it clear this is something different than an article or a post.

What it is not clear from you answer is whether I have to use some special Hugo function or using some system call. Which is the case?
I’d appreciate a code snippet if you can, so I can understand the intricacies of Hugo.

As for the list and single, thanks again for the suggestion. Would an empty file prevent Hugo to generate the 5 files at all, or those will be in any case converted in an HTML file that is later saved in the public folder?


I do this, after a fashion, in my theme cabaret, in that I have site filtering. With my configuration, layouts/partials/list/filtered.html acts like:

{{ range $index, $page := where .Data.Pages "contentType" "post" }}
  {{ if le $index 10 }}
  <section class="post">
    {{ if lt $index 1 }}
      {{ .Render "post/full" }}
    {{ else }}
      {{ .Render "post/summary" }}
    {{ end }}
  {{ else }}
    {{ .Render "post/title" }}
  {{ end }}
{{ end }}

This will render the most recent post in full, the next nine posts in summary, and then all of the remaining posts by title—and it only does it for the “post” section. I have unsectioned content (about, licence, etc.) and other sections that are not included in this particular item.

With respect to the list and single, they will still be generated…but as empty files. I don’t know of a way to tell Hugo, at this point, not to render pages in a particular section. This is also why I mentioned making sure you get the sitemap.xml from the code so that you can forcibly exclude these pages from the sitemap. They’ll be 0-byte files on your site, but if they’re not in the sitemap and aren’t linked from anywhere…no one knows they exist.


If I want content not to generate pages at all then I just make sure my layouts/_default directory is empty. It doesn’t seem to generate an error message of any kind. If there is no default and no type/section specific template then nothing gets rendered. If I need a default for standalone pages I just create a layout folder called “singlepage” and give all individual pages that type or specify it as the layout.