Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

47 lines (26 sloc) 2.649 kB

up, next

GRMustache runtime


There are only three methods that you have to care about when providing data to GRMustache:

  • valueForKey: is the standard Key-Value Coding method, that GRMustache invokes when looking for the data that will be rendered. Basically, for a {{name}} tag to be rendered, all you need to provide is an NSDictionary with the @"name" key, or an object declaring the name property.

  • description is the standard NSObject method, that GRMustache invokes when rendering the data it has fetched from valueForKey:. Most classes of Apple frameworks already have sensible implementations of description: NSString, NSNumber, etc. You generally won't have to think a lot about it.

  • NSFastEnumeration is the standard protocol for enumerable objects. The most obvious enumerable is NSArray. There are others, and you may provide your own. Objects that conform to the NSFastEnumeration protocol are the base of GRMustache loops. You'll read more on this topic in the guide.

For instance, let's consider the following code:

NSDictionary *dictionary = @{ @"count": @2 };
NSString *templateString = @"I have {{count}} arms.";
NSString *rendering = [GRMustacheTemplate renderObject:dictionary fromString:templateString error:NULL];
  1. When GRMustache renders the {{count}} tag, it invokes valueForKey: with the key @"count" on the dictionary. It gets an NSNumber of value 2 as a result.
  2. The description method of the NSNumber returns a string: @"2".
  3. This string is inserted into the rendering: @"I have 2 arms".

In Detail

Mustache does a little more than rendering plain {{name}} tags. Let's review Mustache features and how GRMustache help you leverage them.


    This guide digs into Mustache sections such as {{#section}}...{{/section}}, and the key lookup mechanism.


    Learn how to render template sections as many times as there are objects in enumerable objects such as arrays.


    Control whether a Mustache section should render or not.

up, next

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