Hide content from single template


Is it possible to have content accessible only by the list template?

Thank you!

I don’t think is possible with Hugo. It would be a bit complicated to define which content should be shown on what kind of template.

1 Like

I just found about the ignoreFiles setting, but I couldn’t test it yet.

Well, I tested ignoreFiles. It hides the files for everything. I can’t even use range to read them. So… No way.

I gonna have to move everything to data directory.


Maybe this can help somebody.

I ended setting layout: none on front matter.

1 Like

What a great finding - very smart.

@bep, please, can we rely on this technique?

Yes, this is future safe – but it creates a warning in the log. There is a similar open issue about somethings similar … @budparr may know more …

Thank you!

Aside from data files, layout: none is fine unless you have a lot of pages (or would have to rely on clients to set it).

I do have an open issue on this: https://github.com/gohugoio/hugo/issues/3612 though my biggest reason for it is to improve performance on larger sites where outputting every single page isn’t necessary.

For a hacky workaround, that I would not guess is future-proof, you can create the single template and put nothing in it. It’s been working for me, though it breaks when running benchmark.

I don’t think our needs exactly match. You want to avoid render all pages again and again. I need to create markdown files for parts of pages, being FAQs one of the cases.

But your need is a valid one, for sure!

Do you think layout: none can be part of docs, @digitalcraftsman? I know a lot of developers want to use several MD files for homepages, faqs, sessions of events, etc, etc…

Feel free to add a note to the documentation. Contributions are always welcomed.

1 Like

Done, boss!

I’m curious, what is your specific use case for this? I read the thread above but I don’t see what the idea is behind this and I’d like to learn!

Of course!

  • FAQs, with one MD for every question;
  • features section on homepage;
  • single page sites;

The three cases have occurred to me in the last few months. FAQ is the most common. I can submit the files to different people on team to write the answers. The idea is to split a single MD content into several parts without to write HTML.

how do you put them together and display/render them?

Having a content/faq.md and a bunch of questions within content/faq/:

{{ .Content }}
{{ range where $.Site.RegularPages ".Type" "faq" }}
	<details id="faq__{{ .File.TranslationBaseName }}">
		<summary>{{ .Title | safeHTML | markdownify }}</summary>
		{{ .Content }}
{{ end }}

To make them easy to get, I set their type on frontmatter.

1 Like