But if I restart hugo server, or just run hugo, I get the following error:
Error: Error building site: failed to render pages: render of "page" failed: "/home/chris/projects/hugo/qs4/layouts/preview/single.html:36:27": execute of template failed: template: preview/single.html:36:27: executing "main" at <$mainimg.Resize>: can't evaluate field Resize in type resource.Resource
Looks to me, your image works on a few pages but not all of them. You should really use with or if to test for its presence before trying to resize it or reference it.
That might have worked once, because Hugo live reload only works on the present page by default and this particular one had a mainimg.
Thanks Régis – your answer explains my problem exactly. I hadn’t understood that difference between a live reload and a full restart of Hugo. And although I knew about with I hadn’t thought to use it here.
And thank you for creating the page that Leo mentioned – I’ve learnt a few things from that too.
It’s really worth reading all posts from @regis. I did the same and the sky cleared. He is also very supportive if you ask questions. Learned a lot - very much appreciated.