How to show subsection in Template?

The template vars{{ .Section }} or {{ .Type }} from \post\news\first-news.md shows only “post” not “news”. I wan´t show post (from root), news (subfolder), event (subfolder) etc.

How can i solve this?

Infos: My Single Template ist under \themes\THEME\layouts\post\single.html

Info: hugo.exe v0.14 Windows

1 Like

From http://gohugo.io/content/types/: “Hugo assumes that your site will be organized into sections and each section will use the corresponding type. … each new piece of content you place into a section will automatically inherit the type.”

If you want to have types separate from the section, you must set “type” in the front matter. If you want to do this a lot, I’d recommend creating a “news” archetype.

1 Like

@moorereason

I am having the same issue. I am not able to filter by the sub-folder (sub-section or sub-type).

I have the following folders and files.

[content]
–[post]
----first.md
----second.md
–[comment]
----[first]
---------comment-1.md
---------comment-2.md
----[second]
---------comment-1.md

I created a “comment” archetype in testsite\themes\ft\archetypes. but it didn’t work so I have to move “comment.md” to testsite\archetypes then it works. I have the code below in comment.md.

+++
type="comment"
+++

In single.html, I have this code.

Single.html

<h1>{{.Section}}</h1>
<h2>{{.Title}}</h2>
<p>{{.Content}} </p>

{{ $commentPages := where $.Site.Pages "Section" "comment" }}

{{ range  $commentPages }}
	  <a href="{{ .Permalink }}">
		{{ .Title }} - {{ .Section }} - {{ .Type }} 
	  </a>	
 {{ .Content }} <br/>
{{ end }}

When I go to http://localhost:1313/post/first/, it will show all comments. I like to filter the comments under /comment/first/ folder.

I think I should add a where condition at {{ range $commentPages }} but I am not sure which identifier that I can use to filer it. Could you please give me some pointers on this filtering part?

Thanks!

Hugo has no concept of sub-sections. Top-level sections only.

@bep

Thanks!

I think I managed to get what I want to achieve now. I will share it for feedback after I’ve done a few tests.

Thanks all!