Check if block is empty

Hello,

Is it possible to check if a block is empty within a partial file, or anywhere else for that matter?

Here is the relevant portion of my baseof.html template:

{{ partial "navigation.html" . }}
<div class="main-container">
  {{ block "header" . }}{{ end }}
  <main>
    {{ block "main" . }}{{ end }}
  </main>
  {{ partial "footer.html" . }}
</div>

I have a partial template called navigation.html. In it, i’d like to do something like this:

<nav{{ if ne "header" "" }} class="special-class"{{ end }}>

In other words, if there is something defined for the header block, add a class (or do whatever). Otherwise, if there’s nothing in the header block, don’t do anything.

Thanks y’all for considering this question. Please forgive me if it’s obvious and i missed it.

I wonder if you could use fileExists or readFile in your check

Thanks @zwbetz, i really tried to make this work, but just couldn’t crack it. As a workaround, I ended up taking my templates in another direction, albeit i’d still like to know if this is possible for future projects.