Point at same content file from different sections of the TOC


#1

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?


#2

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.


#3

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


#4

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

type="posts"

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.

EDIT
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.


#5

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


#6

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.


#7

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


#8

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