Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

66 lines (42 sloc) 2.065 kb

up, next


Mustache sections can be controlled by booleans. For instance, the following template would render as an empty string, or as "whistle", depending on the boolean value of the pretty key in the rendering context:


We'll first talk about some simple cases. We'll then discuss caveats.

Simple booleans: [NSNumber numberWithBool:]

The simplest way to provide booleans to GRMustache is to provide objects returned by the [NSNumber numberWithBool:] method:

NSString *templateString = @"{{#pretty}}whistle{{/pretty}}";
GRMustacheTemplate *template = [GRMustacheTemplate templateFromString:templateString error:NULL];

// @"whistle"
[template renderObject:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES]
// @""
[template renderObject:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO]

BOOL properties

Since GRMustache uses Key-Value Coding for accessing context keys, you may also provide objects with BOOL properties.

For instance:

@interface Person: NSObject
@property BOOL pretty;

Person *alice = [Person new];
alice.pretty = YES;

Person *bob = [Person new];
bob.pretty = NO;

[template renderObject:alice]; // @"whistle"
[template renderObject:bob];   // @""

Your custom property getters will work just as fine.

Other false values

GRMustache considers as false the following values, and only those:

  • nil and missing KVC keys
  • [NSNull null]
  • NSNumber instances whose boolValue method returns NO
  • the empty string @""
  • empty enumerables (all objects conforming to the NSFastEnumeration protocol, but NSDictionary -- the most obvious enumerable is NSArray).

They all prevent Mustache sections {{#name}}...{{/name}} rendering.

They all trigger inverted sections {{^name}}...{{/name}} rendering.

up, next

Jump to Line
Something went wrong with that request. Please try again.