Unterminated HTML Comments break if + else + end

I noticed odd behavior with HTML comments today. In my partial, I have:

{{ if .homepage }}<!-- homepage ->{{ else }}<!-- not homepage -->{{ end }}

That’s bad HTML - the first comment is missing a dash in the close. That gives me an error:

ERROR: 2016/01/02 16:34:59 template.go:120: html/template:partials/homepage.html:2:6: {{if}} branches end in different contexts: {stateHTMLCmt delimNone urlPartNone jsCtxRegexp attrNone elementNone <nil>}, {stateText delimNone urlPartNone jsCtxRegexp attrNone elementNone <nil>} in partials/homepage.html

Since I was just changing the file, it was easy to find my typo. Adding that dash makes everything work:

{{ if .homepage }}<!-- homepage ->{{ else }}<!-- not homepage -->{{ end }}

Seems that the HTML comments are being stripped before processing the templates. If this is a feature, we should call it out in the docs because I’ve been using Hugo for more than a year (whoot!) and never realized that I could comment out templates like that.

This is with V0.16, built from GitHub this morning.

Whats the .homepage? And how does it differ from .IsHome?

Playing around with dictionaries. I call the template with:

{{ $homepage := true }}
{{ partial "homepage.html" (dict "context" . "homepage" $homepage) }}

It’s not important - this happens with anything:

{{ if ".homepage" }}<!-- homepage ->{{ else }}<!-- not homepage -->{{ end }}

The HTML comments are stripped out by the html/template package, not Hugo. This Stackoverflow post explains why: