So I'm working with an implementation of the Jade templating language for Go (see https://github.com/go-floki/jade) and I'm running into an interesting "feature" of the language. The code below works as expected, placing and img
element for every headshot.
each $headshot in $object.Headshots
img.img-circle.headshot(src=$headshot)
I then wanted to change it so on the sixth element the image source would be a preset image. However, when I run this code I get an error
each $headshot, index in $cause.Headshots
if index == 6
img.img-circle.headshot(src="/public/images/ellipse.png")
else
img.img-circle.headshot(src=$headshot)
Specifically undefined variable $headshot
. It seems that $headshot
does not exist within the scope of the if
statement. This isn't the first time I've run into this behavior using this implementation and it's frustrating to try to work around. The trouble that it takes made me wonder, is there possibly a reason the language works this way?
Additionally, can anyone think of a way to work around the "feature" in this case? The best I can come up with is to change it later client-side with Javascript.