Feature request : add a `require` method for values that can be nil
Author: NovaliX-DevCreated Sep 3, 2026Updated Sep 14, 2026
LabelsProposal
Right now when a value can be nil we have the default method which produce a default value if the value piped is nil :
{{ $value := ... | default <default-val> }}
I would like to have something similar which produce an error instead when the value is nil.
{{ $value := ... | require <error message> }}
Currently, the only way to do this is to check the value using if conditions :
{{ $value := ... }}
{{ if not $value }}
{{ errorf ... }}
{{ end }}
That can become tedious if we need to ensure many values must not be nil
Doing it with my proposed require function means it can be all be done in one line, making the partial and template code cleaner.
Source: gohugoio/hugo