Can you put Wrapper code around a baseof block that displays if the block is defined

Is it possible in a baseof template to check if a block is defined in a template and render some wrapper content before rendering the block content? I’m transitioning from middleman where this is quite well supported but am still getting familiar with go and hugo.

{{ if block "sidebar" }}
    <div>
        {{ block "sidebar" . }}
            <nav></nav>
        {{ end }}    
    </div>
{{ end }}

You could just put the wrapper div inside the block definition directly. No block definition = no need for wrapper. So the wrapper only renders if the block is present.

Yes, but you end up with much dryer templates with the approach above. You can define all of your wrapper layout code in the baseof layout and then switch out the inner contents layout by layout without having to repeat this.

Thanks again for you advice @pointyfar

For now, I ended up just using frontmatter

  {{ if isset .Params "sidebar" }}
      <div class="md:bg-gray-100 flex w-full md:w-72 h-2 md:h-auto">
        <div class="pt-5 px-5 w-full">
          {{ block "sidebar" . }}
          {{ end }}
        </div>
      </div>
    {{ end }}