Get category name from content folder

Hello, I am in the process of creating my theme. The content is created according to the following scheme:
|- content
|— example/2024/05/19/article_name ← content section name/category

I can get list from pages on url: https://mysite/example/

Is there a way to call the content root section name in the template ← this best for me
Is it possible to get “example”?
use front matter to add metadata to each page (,

folderCategory = 'example'

From your question I understand that you need to know the “section” of a post. The root folders (those folders inside of content) are called section in GoHugo concepts. You should have .Section in the page object saying example for all these posts.

I know it’s sometimes hard to explain something, so if I understand your issue wrong please add more details.

Section documentation is here:

Ok. I need to add root content Section of page (“Example”) to single.html

<h1>{{ root content Section of page }}</h1>
<h1>{{ .Page.section }}</h1>   <- It doesn't work)

In this case need to render:


Capitalize the first letter.

1 Like

hugo v0.126.1-3d40aba512931031921463dafc172c0d124437b8+extended windows/amd64 BuildDate=2024-05-15T10:42:34Z VendorInfo=gohugoio

From the error messages its looks like you’re guessing instead of reading/following the documentation, and screen captures aren’t very helpful.

You are more likely to receive a prompt and accurate response if you post a link to your project’s Git repository.

See Requesting Help.

Let us see your code

Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.

If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.

1 Like

Thank you for your help. It works with section permalink

<a href="{{ .FirstSection.RelPermalink }}">{{ .Section }}</a>

You need to restart the Hugo server.

I’m sorry, but how to get permalink for .Section?

<a href="{{ .Section.Permalink }}"> {{ .Section }} </a>

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.