Since I’m here, I might as well ask about these two strange occurrences.
Partials attempt to execute even when not called.
This one confuses me. I have a partial that I am working on building for a theme. It has known errors in it, so to get the site to build I have commented out or removed the line that calls it. Yet, I am still getting the error:
Of course it’s undefined. I haven’t called the partial. But unless I delete the partial, I cannot build the site to test.
Comments don’t comment anything but themselves
So I tried to comment out the file, by wrapping it in:
{{/*
{{ other template commands here }}
*/}}
But that doesn’t work, because Hugo is still trying to interpret everything inside of the comments. So they seem to be useless unless you go through and add them to every single occurrence of {{ and }}, which for a large chunk of code is just not feasible. Is this expected behavior, and is there any way to comment out code other than removing it?
Apologies if any frustration is making its way into these questions. I’m in debugging hell at the moment.
partials: “parsing” is not “executing”. Hugo parses all templates at the beginning, If you have a syntax error or any other error it will fail. Without seeing your particular setup it’s hard to say if your partial is executed or something else is the error. The followup question shows, that “commented out” might not have been really commented out. So that might be the reason for the error.
comments: yep. There is NO comment to comment out multiple gotemplate tags. You need to comment out every single gotemplate tag. {{/* is the comment, so {{/* other template commands here */}} is the way to comment. Some IDEs with gotemplate support know that and do accordingly if you mark many tags and set to commented.
Thank you for the answers. Frustrating that there’s no simple way to extract blocks of code without outright deleting them, but I guess that’s what we’re stuck with.
Weird. It works as I would hoped it would. But I remember cases, where Hugo complains about things inside of {{/* */}} comments. Testing frantically now. Could it be that is is a recent fix/feature?
I’m slightly worried about my mental faculties here now. Maybe the IDE did show errors by fault, but I am pretty sure that a running Hugo server complained to me about Go-commented Go-template-tags… I spent much time commenting every single tag when I commented out Go code all the time
Hmm, maybe it was a connection of HTML and Go comments… I’ll have to look into this.
Other than that: WHY is the OPs code still parsed with comments around it. Maybe if we can get a sample of @mwaterous’s code it get’s clearer. Maybe it’s one of these cases that made me think it’s not supposed to work?
I swear it wasn’t working. I was getting errors in one of my partials, so I tried to wrap the entire partial in comments until I could debug the error, and it continued to spit out the exact same error. You know what, looking at it again, there was another comment in the file, that probably terminated the first opening comment and the build was breaking on the remainder.