mustache icon indicating copy to clipboard operation
mustache copied to clipboard

Inverted Sections

Open tredoe opened this issue 15 years ago • 7 comments

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

tredoe avatar Jul 01 '10 20:07 tredoe

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

hoisie avatar Jul 01 '10 20:07 hoisie

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

hoisie avatar Jul 01 '10 23:07 hoisie

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

tredoe avatar Jul 02 '10 19:07 tredoe

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

hoisie avatar Jul 02 '10 19:07 hoisie

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 avatar Jul 02 '10 20:07 tredoe

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."

tredoe avatar Jul 02 '10 21:07 tredoe

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

hoisie avatar Aug 24 '10 02:08 hoisie