Turns out recursion is possible in Hugo templates by define
-ing blocks and then “calling” them with template
. (I had thought define
was only for overriding blocks from parent templates, like Django).
The use case was that I wanted to render a nested file tree, e.g.
- dir/
- file1
- file2
- dir2/
- file3
- dir3/
- file4
- file5
And so here’s a slimmed down version of what I figured out: