<commit_before>[up](../../../../GRMustache#documentation), [next](filters.md)

GRMustache runtime
==================

Overview
--------

Mustache defines a few tag types:

- `{{> partial }}` and `{{< partial }}...{{/}}` partial tags, documented in the [Partials Guide](partials.md)
- `{{! comment }}` comment tags, which are not rendered
- `{{ name }}` HTML-escaped variable tags
- `{{{ name }}}` and `{{& name }}` unescaped variable tags
- `{{# name }}...{{/ name }}` regular section tags
- `{{^ name }}...{{/ name }}` inverted section tags
- `{{$ name }}...{{/ name }}` overridable section tags, documented in the [Partials Guide](partials.md)

This guide describes how `{{ name }}`, `{{{ name }}}`, `{{# name }}...{{/ name }}` and `{{^ name }}...{{/ name }}` tags load and render your data.

Variable tags
-------------

Variable tags `{{ name }}` and `{{{ name }}}` look for the `name` key in the object you provide:

```objc
id data = @{ @"name": @"Arthur" };

// Renders "Hello Arthur!"
NSString *rendering = [GRMustacheTemplate renderObject:data
                                            fromString:@"Hello {{name}}!"
                                                 error:NULL];
```

Any [Key-Value Coding](http://developer.apple.com/documentation/Cocoa/Conceptual/KeyValueCoding/Articles/KeyValueCoding.html) compliant object that responds to the `valueForKey:` method can be used.

Dictionaries are such objects. So are, generally speaking, your custom models:

```objc
// The Person class defines the `name` property:
Person *barbara = [Person personWithName:@"Barbara"];

// Renders "Hello Barbara!"
NSString *rendering = [GRMustacheTemplate renderObject:barbara
                                            fromString:@"Hello {{name}}!"
                                                 error:NULL];
```

Remember that `{{ name }}` renders HTML-escaped values, when `{{{ name }}}` and `{{& name }}` render unescaped values.

Objects are usually rendered with the [standard](http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html) `description` method, with two exceptions:

- Your custom objects that take full charge of their own rendering. See the [Rendering Objects Guide](rendering_objects.md) for further details.
- Objects conforming to the [NSFastEnumeration](http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocFastEnumeration.html) protocol:

Variable tags render each of the enumerable objects:

```objc
id data = @{ @"voyels": @[@"A", @"E", @"I", @"O", @"U"] };

// Renders "AEIOU"
NSString *rendering = [GRMustacheTemplate renderObject:data
                                            fromString:@"{{voyels}}"
                                                 error:NULL];
```

This especially comes handy with your custom [rendering objects](rendering_objects.md): you may think of Ruby on Rails' `<%= render @items %>`.

Expressions
-----------

Variable tags render simple keys as seen above, and, more generally, *expressions*, such as the key path `person.name` and the filtered expression `uppercase(person.name)`.

```objc
Person *craig = [Person personWithName:@"Craig"];
id data = @{ @"person": craig };

// Renders "Hello CRAIG!"
NSString *rendering = [GRMustacheTemplate renderObject:data
                                            fromString:@"Hello {{ uppercase(person.name) }}!"
                                                 error:NULL];
```

GRMustache first looks for the `person` key, extracts its `name`, and applies the `uppercase` built-in [filter](filters.md). The variable tag eventually renders the resulting string.


Section tags
------------

The rendering of section tags such as `{{# name }}...{{/ name }}` and `{{^ name }}...{{/ name }}` depend on the value attached to the `name` expression.

Generally speaking, *inverted sections* `{{^ name }}...{{/ name }}` render when *regular sections* `{{# name }}...{{/ name }}` do not. You can think of the caret `^` as the Mustache "else".

Precisely speaking:

### False sections

If the value is *false*, regular sections are omitted, and inverted sections rendered:

```objc
id data = @{ @"red": @NO, @"blue": @YES };

// Renders "Not red"
NSString *rendering = [GRMustacheTemplate renderObject:data
                                            fromString:@"{{#red}}Red{{/red}}{{^red}}Not red{{/red}}"
                                                 error:NULL];<commit_msg>Wording<commit_after>[up](../../../../GRMustache#documentation), [next](filters.md)

GRMustache runtime
==================

Overview
--------

Mustache defines a few tag types:

- `{{> partial }}` and `{{< partial }}...{{/}}` partial tags, documented in the [Partials Guide](partials.md)
- `{{! comment }}` comment tags, which are not rendered
- `{{ name }}` HTML-escaped variable tags
- `{{{ name }}}` and `{{& name }}` unescaped variable tags
- `{{# name }}...{{/ name }}` regular section tags
- `{{^ name }}...{{/ name }}` inverted section tags
- `{{$ name }}...{{/ name }}` overridable section tags, documented in the [Partials Guide](partials.md)

This guide describes how `{{ name }}`, `{{{ name }}}`, `{{# name }}...{{/ name }}` and `{{^ name }}...{{/ name }}` tags load and render your data.

Variable tags
-------------

Variable tags `{{ name }}` and `{{{ name }}}` look for the `name` key in the object you provide:

```objc
id data = @{ @"name": @"Arthur" };

// Renders "Hello Arthur!"
NSString *rendering = [GRMustacheTemplate renderObject:data
                                            fromString:@"Hello {{name}}!"
                                                 error:NULL];
```

Any [Key-Value Coding](http://developer.apple.com/documentation/Cocoa/Conceptual/KeyValueCoding/Articles/KeyValueCoding.html) compliant object that responds to the `valueForKey:` method can be used.

Dictionaries are such objects. So are, generally speaking, your custom models:

```objc
// The Person class defines the `name` property:
Person *barbara = [Person personWithName:@"Barbara"];

// Renders "Hello Barbara!"
NSString *rendering = [GRMustacheTemplate renderObject:barbara
                                            fromString:@"Hello {{name}}!"
                                                 error:NULL];
```

Remember that `{{ name }}` renders HTML-escaped values, when `{{{ name }}}` and `{{& name }}` render unescaped values.

Objects are usually rendered with the [standard](http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html) `description` method, with two exceptions:

- Your custom objects that take full charge of their own rendering. See the [Rendering Objects Guide](rendering_objects.md) for further details.
- Objects conforming to the [NSFastEnumeration](http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocFastEnumeration.html) protocol:

Variable tags render each of the enumerable objects:

```objc
id data = @{ @"voyels": @[@"A", @"E", @"I", @"O", @"U"] };

// Renders "AEIOU"
NSString *rendering = [GRMustacheTemplate renderObject:data
                                            fromString:@"{{voyels}}"
                                                 error:NULL];
```

This especially comes handy with your custom [rendering objects](rendering_objects.md): you may think of Ruby on Rails' `<%= render @items %>`.

Expressions
-----------

Variable tags render simple keys as seen above, and, more generally, *expressions*, such as the key path `person.name` and the filtered expression `uppercase(person.name)`.

```objc
Person *craig = [Person personWithName:@"Craig"];
id data = @{ @"person": craig };

// Renders "Hello CRAIG!"
NSString *rendering = [GRMustacheTemplate renderObject:data
                                            fromString:@"Hello {{ uppercase(person.name) }}!"
                                                 error:NULL];
```

GRMustache first looks for the `person` key, extracts its `name`, and applies the `uppercase` built-in [filter](filters.md). The variable tag eventually renders the resulting string.


Section tags
------------

The rendering of section tags such as `{{# name }}...{{/ name }}` and `{{^ name }}...{{/ name }}` depend on the value attached to the `name` expression.

Generally speaking, *inverted sections* `{{^ name }}...{{/ name }}` render when *regular sections* `{{# name }}...{{/ name }}` do not. You can think of the caret `^` as the Mustache "unless".

Precisely speaking:

### False sections

If the value is *false*, regular sections are omitted, and inverted sections rendered:

```objc
id data = @{ @"red": @NO, @"blue": @YES };

// Renders "Not red"
NSString *rendering = [GRMustacheTemplate renderObject:data
                                            fromString:@"{{#red}}Red{{/red}}{{^red}}Not red{{/red}}"
                                                 error:NULL];
{'fraction_non_alphanumeric': 0.16469008726784515, 'fraction_numerical': 0.0, 'mean_word_length': 2.8022118247554233, 'pattern_counts': {'":': 10, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 40, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '62745', 'n_tokens_mistral': 2499, 'n_tokens_neox': 2341, 'n_words': 789}