Point at same content file from different sections of the TOC

I need to point at the same content file from different sections of a TOC. This is to prevent having multiple copies of a content.md file in different sections, which will make upkeep very difficult. Is this possible?

You can get it by type in your list.html.

First declare the section where you want the post of another section to appear.

{{if eq .Section "posts"}} {{ range $i, $e := (where .Site.Pages "Type" "posts") }} .... {{ end }} {{ end }}

And in your post’s frontmatter simply declare

type = "posts"

This will render all of the posts that should be rendered in that section normally, plus posts with said type.

@alexandros Thanks for that, we’ll give it a go.

A word of caution.
I’ve tested this a bit further and this is most likely a hack.

It works only if you give the post type the same name as the section where you want this post to appear.

Meaning set the frontmatter


For section posts

Perhaps Hugo’s gurus like @bep or @rdwatters have a better way to point to the same content file from different sections, than what I posted above.

Interesting. It seems that posts already have their type set according to the section they originally belong to. Meaning a piece of content under /posts/ already has type = "posts" even if it’s not explicitly declared in the frontmatter.

Does the fact we are using a recursive template to nest the TOC items cause any issues that you know of?

No idea. But with what I posted above you can list a post under two sections maximum.

The one where it lives under e.g. /post/ and the one you define in the frontmatter’s type e.g something-else.

I’m also interested to see if there is a better way to do this.

Two sections may suit our purposes, but it would be nice if there is a more flexible solution, if it’s possible. Thanks again.

Just thought I’d bump this, to see if anyone else had a way to solve this?