Does partials just works with type declared in content?

Hi all, my first question here.

I have some partials working fine in index layout.
So I have a content folder ie. ‘about-us’ with index.md
So I created a layout folder with same name ‘about-us’ with single.html and added some partials, same that are being used in index layout. But can’t render these partials without ‘type: about-us’ declarated in index.md.

This is required? The point is that looks like layout was working fine but without partials until add type in front matter.

Make sense? Or I’m missed something?
Thank you.

I’m probably missing some context here: But partials (as in the templates you load with the partial or partialCached function) is only connected by its name, so if you do:

{{ partial "foo.html" }}

Assuming such partial exists either inline or in /layouts/partials, it can be used from any template.

Need to know more about what layouts are present but, a directory with an index.md is a page bundle rather than a section.
By default this means it will use a default page single.html rather than a section/single.html (which is why adding the type key worked).

Hi @bep adding the context…

In my /layouts/index.html i have

{{ define "main" }}
  {{ partial "sections/section-intro.html" . }}
  {{ partial "sections/section-technology.html" . }}
  {{ partial "sections/section-price-quote.html" . }}
  {{ partial "sections/section-features.html" . }}
  {{ partial "sections/section-numbers.html" . }}
  {{ partial "sections/section-testimonials.html" . }}
  {{ partial "sections/section-clients.html" . }}
  {{ partial "sections/section-certified.html" . }}
{{ end }}

This is working fine.

I created:
/content/about-us/index.md
with this code:

---
title: "About Us"
date: 2023-01-10T01:57:32-03:00
draft: false
menu:
  main:
    weight: 2
---

Test

And I created a layout for this content in:
/layouts/about-us/single.html
with this code:

{{ define "main" }}
  <small>Single template</small>
  {{ .Content }}
  {{ partial "sections/section-technology.html" . }}
  {{ partial "sections/section-price-quote.html" . }}
  {{ partial "sections/section-features.html" . }}
  {{ partial "sections/section-certified.html" . }}
{{ end }}

So these partials don’t render, looks that are ignored. And after trying many things and changes I discover that adding this type in front matter, solved the issue and render partials as expected.

---
title: "About Us"
date: 2023-01-10T01:57:32-03:00
draft: false
menu:
  main:
    weight: 2
type: about-us
---

Test

Make sense now?
In my mind, just adding a layout folder with same content name and single.html layout need to render correct.

So my question is about type param in content md is required or I did some mistake.

Thank you.

Hi @andrewd72, I understand the point is that was using correct single.html layout but the partials inside were not rendering, just with type as explained in last comment.

A layout folder will work with “type:” set or for section, you just have a normal page (type: page)
Hugo lookup order

Type
Is value of type if set in front matter, else it is the name of the root section (e.g. “blog”). It will always have a value, so if not set, the value is “page”.

If about-us was a section it would look up that folder for a template.

I struggled with the template lookups at first.

1 Like

This might be helpful:
https://discourse.gohugo.io/t/41812/6

And all partials must be in layouts/partials.

1 Like

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