hoisie / mustache

The mustache template language in Go
MIT License
1.1k stars 224 forks source link

Inverted Sections #6

Open tredoe opened 13 years ago

tredoe commented 13 years ago

Hi! There is a useful section that has not been implemented. The Inverted Sections which begins with a caret (hat) and ends with a slash.

{{^foo}}
{{/foo}} 

http://mustache.github.com/mustache.5.html

hoisie commented 13 years ago

Thanks for reporting this. I actually didn't know this feature existed!

hoisie commented 13 years ago

Just pushed some initial code that should support most cases, though I still need to add support for zero-length arrays or slices.

tredoe commented 13 years ago

Hoisie thanks for add it so fast.

But I get: line 7: unmatched close tag

http://github.com/kless/goweb-identity/blob/2197ffa784e0ec356ac57486bd446f6c1bf5f99e/identity/tmpl/register.html

Note that 'use-email' has 'true' as value: http://github.com/kless/goweb-identity/blob/2197ffa784e0ec356ac57486bd446f6c1bf5f99e/identity/view.go#L25

hoisie commented 13 years ago

Ugh, this is probably related to the change in strings.Split

tredoe commented 13 years ago

Sorry! The problem was because I re-compiled Go and goinstalled mustache but I didn't update it, so I could not use the inverted section.

Anyway, with the last change in strings.Split(), there would change the '0' to '-1'.

http://groups.google.com/group/golang-nuts/browse_thread/thread/efc6eca11122105e/c36738bc8339ba0b

tredoe commented 13 years ago

I'm testing it and the code inner of the inverted section is always rendered, when I've passed a key to "false", "" (empty), and without the key.

"While sections can be used to render text one or more times based on the value of the key, inverted sections may render text once based on the inverse value of the key. That is, they will be rendered if the key doesn't exist, is false, or is an empty list."

hoisie commented 13 years ago

Ah, I ran into the issue you were having. It should be fixed now. Care to test again?