HUGO

Block in a partial and defining in a page

Hi,

I’ve put a block in a partial1.html

{{ block "partial1content" }}Default partial content{{ end }}

Then I’ve tried to define the content in a template.

{{ define "partial1content" }}Some other sidebar content{{ end }}
{{ partial "partial1.html" . }}

However it never seems to make it into the partial?

If I plonk the partial template contents into the main template, then it all works as expected.

I am guessing that the scope of the block is restricted to the partial, whereas being in the template it works as expected.

Is there any way to make this work?

What I was trying to achieve is putting a .TableOfContents into a sidebar. I actually want the sidebar to have different content depending on where I am in the site.

(btw if I put .TableOfContents into the partial it doesn’t work)

Thanks!

Blocks are reserved for the baseof.html templates only.

I just filed https://github.com/gohugoio/hugo/issues/3929, which I believe would address this.

I also need to define blocks inside partials for better code organization.

Is there any alternative way?

2 Likes

Are they any alternatives? @johnson did you find something?