Issue with block and define

I got the following structure:

layouts
  -> _default
     baseof.html
  -> pages
     contact.html
  -> partials
     contactform.html
  index.html

baseof.html:

...
{{ block "header_css" . }}{{ end }}
...

index.html:

...
{{ define "header_css" }}{{ end }}
...

contact.html:

...
{{ define "header_css" }}{{ end }}
...

contactform.html:

...
{{ define "header_css" }}
  {{ $tomSelectCSS := resources.Get "css/tom-select.bootstrap5.css" }}
  {{ if .Site.IsServer }}
    <link rel="stylesheet" href="{{ $tomSelectCSS.RelPermalink }}">
  {{ else }}
    <link rel="stylesheet" href="{{ ($tomSelectCSS | minify | fingerprint).RelPermalink }}">
  {{ end }}
{{ end }}
...

This works for the contact page, but the problem is that the stylesheet shows up on the index page when viewed in the browser. I can’t figure out if this is by design or error

I am sure I did not get all of that. Too much missing around the snippets. No way to replicate that.

But you cannot define a block in a partial. That may explain taht the output is weird.

To get in detail I would recommend to share a replayablw example.

tried moving the css out of the partial, that fixed things.

Is this limitation by design?

Yes.

quote=“tyr84, post:3, topic:51910”]
moving the css out of the partial
[/quote]

What ever that means…

You can define multiple blocks in baseof.
Then define these blocks in a layout like index.html. and call partials in blocks.

baseof.html

<html>
  <head>
    {{ block "head"....
  </head>
  <body>
    {{ block "main" ... }}
  </body>

index.html

{{ define "head" }}
  {{ partial "contactform" . }}
{{ end }}
{{ define "main" }}
  {{ .Content }}
...

There’s more, like defaults for blocks, omit a definition to skip a block…
Check the docs