TLDR: why doesn’t hugo server indicate error when template fails to render for some reason?
Hi, I’ve used Hugo a bit but wanted to start from scratch building & understanding my own theme.
I’ve created an _index.md in content and some other content as well. I created an empty theme. Then I copied the template code from the Homepage Template documentation into an index.html under layouts, to create a “homepage template”.
My home page (content/_index.md) fails to render anything, unless I get rid of all of the example template except {{ .Content }}
I’m not looking for the answer of why this doesn’t work, I’m looking for the answer of how I can learn this myself by observing log files and hugo server output - this is a great way to learn, watch the log and start removing things until it works. I would expect hugo server to tell me something is wrong (“template not found”, etc) rather than rendering nothing. I am launching hugo server like this:
hugo server --log --logFile ./hugo.log --verbose --verboseLog -D --cleanDestinationDir
Neither stdout or the logfile shows any errors with the example homepage template code, it just doesn’t render anything.
There is no error because the homepage template defines a main block which will need to be rendered by a base template - so there is in this case nothing to render.
If you include a baseof.html in layouts/_default, the homepage template will then get called.
But now, we see that if there is no “summary” partial defined, and we try to explicitly {{ .Render “summary” }} as in the example, we also do not receive any kind of error or warning from hugo - it just skips this portion of the template.
I thought I might find something documented in Template Lookup Order or Partial Template Lookup Order that would indicate what happens in the event no template is found - but unless I’ve overlooked it, this isn’t documented.
Is it expected behavior that if I explicitly {{ .Render "summary" }} and no summary template exists, there is no info, warning, or error from Hugo?
Running v0.40-DEV, i can confirm .Render in list templates does not produce any warning/error if the template called does not exist.
However, by taking a look at the source code, it seems to me that from the template we are calling page Render (line 144) which itself calls page output Render (line 115) which is supposed to produce an error message is the template is missing line 118:
helpers.DistinctErrorLog.Printf("in .Render: Failed to resolve layout %q for page %q", layout, p.pathOrTitle())
But i don’t see this message when attempting to render a non-existing template either.