HUGO

Conditional define and define within partials

In my single.html, I have define blocks that override the ones in baseof.html

{{ define "main" }}
...

I am trying to have different defines based on some condition, conceptually:

{{ if (cond) }}
{{ define "main" }}
...
{{ end }}
{{ else }}
{{ define "main" }}
...
{{ end }}
{{ end }}

That didn’t work. But I can instead put the if condition inside the define.

But I have several defines that I would like to all toggle based on the condition. This makes it so that I have to separate related content based on the conditional to different define blocks. Not a clean solution.

I tried to use partial here:

{{ if (cond) }}
{{ partial "foo" . }}
{{ else }}
{{ partial "bar" . }}
{{ end }}

But inside the partials “foo” and “bar” the defines don’t do anything. So I am guessing that a define within a partial are not allowed.

If you have some suggestion on how to tackle this problems, please let me know.

Note: there are some overlaps with the following: