Assign content to multiple sections

hi all,

i’m new to hugo/go and trying to use hugo as a small cms replacement. i’ve played arround with menus, taxonomies and terms to achieve two “simple” things, but wasn’t successfull.

first goal, place content in multiple sections/navigation:

for example asume the following site structure:

- sports
  - events
   - (content with pictures)

- pictures
  - 2017
   - sportevents
    - (same content as under /sports/events/)

it should be possible to reach 2017-football through multiple navigation paths:




with menus only it’s not possible (with my skills), with taxonomies etc. i’m not able to build a working sidebar navigation.

this leads me to a second/similar “organisational” problem:

- pictures
 - 2017
  - sportevents
  - hillclimbing
  - diving

pictures should contain all post’s from subdirectories, 2017 should contain all posts’s from 2017 subdirectories and so on.

so my question is, is it possible to get this kind of content assingment working without a huge bunch of programming, e.g. build lists for every section, configure every menu in config.toml etc. (i’m not a good programmer) ?

the structure is almost static, so an initial big work wouldn’t be a problem.

thanks for your input!

Well… Regarding your first problem about assigning content to multiple sections -as you put it- this is not very straightforward in Hugo.

There are two options

  1. Go by the book.
    If you read the Docs you’ll see that the way to do this is through the use of taxonomies and then create multiple layouts for different lists and use .GetPage in your templates. This the safe and future proofed version.

  2. Don’t follow the rules.
    In this forum there have been topics about dynamic taxonomies filtering, custom content filters and the like. But all of these are currently considered hackish -I’m afraid- but these will give you what you want without having to make lots of templates for different lists. However if you go down this route it is quite possible that a future Hugo update might break something in the functionality of your site.

What you’re asking for has no easy answer and it’s up to you to choose what you want to do.

Now regarding your second problem. Read about Nested Sections. It’s trivial to list all posts from several nested sections under /pictures/ and then everything under /2017/.

I just remembered that since Hugo 0.32 there is support for symbolic links. I haven’t used them for assigning content to multiple sections, but now that I think of it I’ll check this out and share my findings.

1 Like

Symbolic links work but the end result is duplicate pages (unfortunately).

I’ve opened a Github Issue to make symbolic links respect the context of their original content files.

Let’s see what the Devs think…

Ah! I just discovered that it is possible to disable the page duplicates by setting the URL in the front matter of the original content file! The downside is that this is another front matter parameter that needs to be entered manually. But that is a very small price to pay.

No need for .GetPage, no need for several list templates and no more Taxononomies weirdness.

Symbolic links to content files are the easiest way in Hugo to assign content to multiple sections and nested sections.

@bep Thank you so much for symbolic links! I just realized what an amazing feature it is.

As I said about it in the thread, you will still have duplicates, but they end up with the same filename.

True. I got rid of the duplicate permalinks with the URL front matter. But I get duplicates on the main section.

And with a simple param check I also removed the duplicates from the list page of the main section @bep

And double checked my /public/ folder and no duplicates are in sight.

I now understand how symbolic links are meant to generate duplicates by design. But since I managed to remove these duplicates I will be using this as it makes my life much easier.

And I just can’t see how it could break in a future update. Unless symbolic links are removed from Hugo and I very much doubt that this will happen.

There was a lot of activity in this thread, and I am gonna be a wet blanket and point out two things about the question about “navigation paths”:

  1. Humans don’t expect to find the same content at different URLs
  2. Search engines therefore don’t expect to find the same content at different URLs

Pick whichever one applies more to your goals, but there is it. If you do somehow figure out how to do that with the URLs, your site won’t benefit from it. I wish I had a good information architecture book suggestion, but I am sure if you ask around you can find good resources to go over the vocabulary used, so then you can describe the experience you want for your visitors, and then figure out how to structure it in the way that helps them. :slight_smile:

It depends. For product sites that is a common scenario.

e.g. the same backpack listing needs to be accessible under the general /backpacks/ and then under the more specific /backpacks-for-17-inch-laptop/

If you have content1, content2, content3 and compose content1+content2 in one URL and content1+content2+content3 in another, you will have duplicate content – but not same. And the above pattern is useful to avoid DRY in some situations.

Yes. But it’s not simple to do this with Hugo. At least I haven’t found it. And believe me I’ve tried several times in the past few months…

If I go down the taxonomies route I end up with useless taxonomy URLs, if I disablekinds for taxonomies sometimes the taxonomies stop working altogether and sections (nested or not) render empty… .GetPage requires different templates for different lists, (that’s too much work IMO but I guess it’s the only way).

And regarding my unconventional use of symbolic links for this issue.

Even though I eliminated duplicates from list pages I am unable to remove the identical duplicate pages from the sitemap.xml. Since the symbolic links are under Nested Sections there is no easy way to hide them. eg. A param in does not hide .Data.Pages under a Nested Section.

Anyway. My head kind of hurts and I have other very urgent things to do, so I guess that I will try to figure out a simple way to assign content to multiple sections and nested sections some other day…

And my apologies to the OP for hijacking the thread.

I was referring to having two pieces of content (each from a different Of course listings, transclusion and others will bring content together.

I was trying to nudge the OP away from using two files that are the same content. :slight_smile:

Hi all,

thanks for your valuable feedback, it helped me a lot!

first, @maiki my question was about “how to solve”, not “why” :wink: The site i’m working on is private/internal, so no need for SEO stuff etc.

back on topic, for listing subsection content i’m using this now (own section list.hmtl):

{{ range where .Site.Pages "Section" "in" (slice "blah")) }}

Every content inside /blah and subdirectories has now a frontmatter “Categories: [“blah”]”, this works for me.

Multiple sections can be combined with:

{{ range where .Site.Pages "Section" "in" (slice "blah" "blub") }}

for accessing content through multiple paths (taxonomy/term) i’m just playing with some templates, looks like i’m on a good way :smiley:


1 Like