Include partial disqus html only in specific section

Hi everyone:) I’m so glad that I found hugo! Thank you everyone so much! I do have a question though and I’d be glad to receive a pointer to any ressource that helps explaining this.

So the issue is the following. I wanted to include Disqus on my little website. So I added the partial-template to my single.html. However, I only want to render it for a certain section called “posts”. Under the content directory, my structure loooks like this:

.
├── about.md
├── contact.md
├── food
├── map
└── post

So I looked on the hugo site and included the following if-else statement to only render the _internal/disqus.html for the post section:

{{ if eq .Section "blog"}}
  {{ template "_internal/disqus.html" . }}
{{end}}

However, it’s still including disqus on all sites and I’m not really sure what onvious thing I’m missing…

There is no section blog, so it shouldn’t match. I’d report this as a bug.

    {{ if eq .Section "posts"}}
      {{ template "_internal/disqus.html" . }}
    {{end}}

This should work.

1 Like

Thank you very much for the answer:) Although I messed this up (I wanted to write {{if eq .Section "post" }}) I still get the same behavior and the disqus-html rendered onto almost all my pages. Only the map-page has it not. The difference in the map-folderstructure is, that the subdirectory of map only has one file called _index.md.

I have a similar issue with putting the partial contact.htmlonly on my contact page. The contact.md lies directly under content, but as far as I know this gets rendered to contact/index.html. So I put

{{ if eq .Section "contact"}}
  {{partial "contact.html" . }}
{{end}}

this into my single.html, but it also doesn’t work properly. I think I’m just missing something really basic about the structure of HUGO and what the .Section-variable here actually means…

Instead of what you have above try variations of
{{ if in .Permalink "page or section" }}
and
{{ if in .Section "section-name" }}

1 Like

@alexandros Thank you very much! I tried a lot, but I just don’t get it to work:/
I think I’m just not getting exactly what the Variable .Section actually means and where the difference to something like .FirstSection is. I tried to read https://gohugo.io/content-management/sections/ and try out a lot. But Disqus still gets rendered on almost all pages…

Please share the source code of your project.

We need to see the full context of the templates.