Hiho,
I am quite new to Hugo and struggled my way down with the template lookup rules… So I found warnidf and used it to output a warning if a block in baseof.html is not defined in the layout file. Helped me out a lot.
very cool that the warning can be suppressed ![]()
Although it gives me the info I was looking for I suggest two changes to the output to make it more readable produce less noise.
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
{{ block "missing" . }}
{{ warnidf "w-block-undefined" "undefined block for _defaults/baseof.html rendering page "}}
{{ end }}
<main>{{ block "main" . }} {{ end }}</main>
</body>
</html>
The output I get is:
hugo --cleanDestinationDir --gc --logLevel info
Start building sites …
hugo v0.123.6-92684f9a26838a46d1a81e3c250fef5207bcb735+extended windows/amd64 BuildDate=2024-02-28T18:29:40Z VendorInfo=gohugoio
INFO static: removing all files from destination that don't exist in static dirs
INFO static: syncing static files to \ duration 11.0497ms
INFO build: step process substep collect files 8 files_total 8 duration 511.1µs
INFO build: step process duration 511.1µs
INFO build: step assemble duration 0s
WARN undefined block for _defaults/baseof.html rendering page
You can suppress this warning by adding the following to your site configuration:
ignoreLogs = ['w-block-undefined']
INFO build: step render substep pages site en outputFormat html duration 14.858ms
Wish
- omit the You can suppresss this warning message
- it’s clearly stated in the fmt.Warnidf docs
- I would suppose users implementing that, know about
- an advanced feature.
- change the output to automatically include the id
- so in normal use case this will be a one liner that can be easily grabbed when parsing the logs.
- fits to the loggin style
So utilization of warnidf would be like that:
{{ warnidf "w-block-undefined" "for _defaults/baseof.html rendering page"}}
{{ warnidf "w-0001" "undefined block for _defaults/baseof.html rendering page"}}
with the following results (or similar)
INFO build: step process substep collect files 8 files_total 8 duration 0s
INFO build: step process duration 0s
INFO build: step assemble duration 0s
WARN w-undefined-block for _defaults/baseof.html rendering page
WARN w-0001 undefined block for _defaults/baseof.html rendering page XXX
or
WARN [w-undefined-block] for _defaults/baseof.html rendering page
WARN [w-0001] undefined block for _defaults/baseof.html rendering page XXX
p.s. ofc I would like to know which source file is currently rendered but that’s another story ![]()