[SOLVED] Exclude a post type from rendering, but not from the list?

I have a section - let’s call it articles - where are two post types:

  1. article, which are standard posts directly on the website (Example)
  2. link, which obviously are links to external articles (Example)

Both of them are shown in a list, linked either to the internal or external article (see here). External articles are marked in the frontmatter of their files and the URL is there as a parameter as well.

Now I try to exclude the links from rendering, so that they aren’t messing up my code (they aren’t shown anyway).

I already tried to give them a type and exclude them with disableKinds. But this was a misunderstanding, since there can’t be more than one type in a section and disableKinds can’t disable specific types.

So, how do I do that? Is there even a way? They still should be visible in the list.

Please read Requesting Help and update your post with relevant information to help us assist you.

For instance, we don’t know the code you are using to render the list. What you are asking seems really straightforward, but I don’t know what to suggest based on your current situation.

The basic answer is, when you range over the content exclude the links, either by type or some other criteria (such as have a link front matter parameter).

@maiki That’s a lot of code, but sure… :smiley: I better link directly to my github repository.

What do you mean by excluding them from rendering and yet have them on the list?

Do you mean that you don’t want these link posts to have their own permalink rendered i.e. single page?

Exactly. In the list there should be shown internal and external articles, but external links shouldn’t have a single page rendered. :wink:

Well the way to go would be to use Headless Leaf Bundles for these links and render them on your lists with .Site.GetPage


I do have one suggestion though. From your link over here I see that you are using a headless = "true" front matter parameter and yet you have not configured the Headless Leaf Bundle properly. Please read the above link from the Docs.

Also disableKinds has the following allowed values "page" , "home" , "section" , "taxonomy" , "taxonomyTerm" , "RSS" , "sitemap" , "robotsTXT" , "404" This is a general configuration setting. As you found out you cannot use it the way you mentioned in your first post.

Thanks! So I was on the right way, but didn’t make it through. :laughing: I suppose, I should dig into it a bit more.

Without looking at your source as well, it seems that a list of links (with no corresponding pages within your site) is a good fit for using a data file rather than creating individual markdown files, which are better suited for content…

1 Like

@mirkoschubert Yes. Data Templates is the other way to do this. And it’s probably more suited for your use case.

High five @rdwatters :raised_hands:

1 Like

I thought about a data template, too. But this list contains not only external links (where indeed no markdown files are needed) but also internal posts (which have to have markdown files) :wink:

So I would have to create a data template with the external links and merge them together with the articles somehow…

Interesting. So this sounds like (again, without looking at source) a matter of reconsidering your current source organization. If these are two different directories, why muddy the two different content types within that directory, especially if they’re pointing to different sites? (I only suggest this, btw, since it looks like you have <10 links so far.) You could then remove your current external attribute within front matter and create separate archetypes for each of the types (i.e. an external link that has its own page on your site vs an external link that doesn’t have its own page). Then you can disable everything in the external directory and save yourself some steps…

That said, if the markdown files for external sites don’t have .Content, your conditional could be as simple as {{with .Content}}, etc. There are multiple options here for you, including the headless option already mentioned by @alexandros, but I guess it depends on your workflow preferences…

An update for all who have the same problem:

I found a simple solution, which is suitable for me. Since all external links have a type: link in the frontmatter and Hugo doesn’t render empty layouts, I just created an empty file under /layouts/link/single.html - problem solved! :smile:

This way I don’t need headless bundles or data templates and achieved the same outcome.

Btw, @rdwatters, when I’m finished there will be hundreds of links and quite a few articles. :wink:

1 Like