Hello,
I would like to utilize the parent contents of a block in a child template.
Use case: _default/baseof.html
<body class="{{- block "body_classes" . }}o-container{{- end }}">
Then, in child template index.html
:
{{ define "body_classes" }}
SUPER HERE????
u-background-light3
{{ end }}
Django exposes a variable in the child block:
If you need to get the content of the block from the parent template, the
{{ block.super }}
variable will do the trick. This is useful if you want to add to the contents of a parent block instead of completely overriding it. Data inserted using{{ block.super }}
will not be automatically escaped (see the next section), since it was already escaped, if necessary, in the parent template.
Is there anything similar in Hugo?
I could do this:
<body class="o-container {{- block "body_classes" . }}{{- end }}">
But I like having the option of overriding the whole thing, or being able to append.
This can also be helpful technique for meta tags, like the <title>
if you want to keep existing copy, and put more copy before or after.
I am probably overlooking something in the manual?