"empty" section tag #4

foca opened this Issue Oct 6, 2009 · 6 comments


None yet

4 participants

foca commented Oct 6, 2009

When declaring a section, it'd be nice to have an if empty/else tag, like django's {% empty %} tag. Something like:

{{# collection }}
  <li>{{ name }}</li>
{{~ collection }}
  Nothing to see here.
{{/ collection }}

As to what symbol should be used, no idea. I'd actually like to use ! for this, # for comments, and something else for new sections/booleans (maybe ?). But that's just me :)

judofyr commented Oct 6, 2009

What would happen if collection is a boolean?

EDIT: Disregard that. It would render the block if it's false.

defunkt commented Oct 7, 2009

I'd like the syntax to match ctemplate's, so I don't really want to change # or !.

judofyr commented Oct 7, 2009

Here's a simple patch (+ test - docs): http://pastie.textmate.org/private/ytwa6kty4vpaillktgn2qw

defunkt commented Oct 7, 2009

I'm just not sure about this.

Why not define an collection_empty? method and use that?

Other template languages based on ctemplate (such as json-template) seem to trend toward fewer features rather than more.

json-template supports this functionality using the syntax {.or}

defunkt commented Oct 11, 2009

I don't really want Mustache's syntax to stray from ctemplates. Please re-open, comment, or email if, in the future, you find yourself badly needing this feature.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment