Inherits from NSObject
Declared in GRMustacheTemplate.h

Overview

The GRMustacheTemplate class provides with Mustache template rendering services.

Companion guide: https://github.com/groue/GRMustache/blob/master/Guides/templates.md

Tasks

Creating Templates

Configuring Templates

  •   baseContext

    The template’s base context: all rendering start from this context.

    property

Rendering Templates

Properties

baseContext

The template’s base context: all rendering start from this context.

@property (nonatomic, retain) GRMustacheContext *baseContext

Availability

Discussion

Its default value comes from the configuration of the source template repository. Unless specified, it contains the GRMustache standard library.

Declared In

GRMustacheTemplate.h

Class Methods

renderObject:fromResource:bundle:error:

Renders an object from a bundle resource template.

+ (NSString *)renderObject:(id)object fromResource:(NSString *)name bundle:(NSBundle *)bundle error:(NSError **)error

Parameters

object

An object used for interpreting Mustache tags.

name

The name of a bundle resource of extension “mustache”.

bundle

The bundle where to look for the template resource. If nil,

           the main bundle is used.
error

If there is an error during rendering, upon return contains an

           NSError object that describes the problem.

Return Value

A string containing the rendered template.

Availability

Discussion

If you provide nil as a bundle, the resource will be looked in the main bundle, with a “mustache” extension.

The template resource must be encoded in UTF8. See the GRMustacheTemplateRepository class for more encoding options.

Declared In

GRMustacheTemplate.h

renderObject:fromString:error:

Renders an object from a template string.

+ (NSString *)renderObject:(id)object fromString:(NSString *)templateString error:(NSError **)error

Parameters

object

An object used for interpreting Mustache tags.

templateString

The template string.

error

If there is an error during rendering, upon return

                   contains an NSError object that describes the problem.

Return Value

A string containing the rendered template.

Availability

Declared In

GRMustacheTemplate.h

templateFromContentsOfFile:error:

Parses a template file, and returns a compiled template.

+ (instancetype)templateFromContentsOfFile:(NSString *)path error:(NSError **)error

Parameters

path

The path of the template.

error

If there is an error loading or parsing template and

             partials, upon return contains an NSError object that
             describes the problem.

Return Value

A GRMustacheTemplate instance.

Availability

Discussion

The template at path must be encoded in UTF8. See the GRMustacheTemplateRepository class for more encoding options.

Declared In

GRMustacheTemplate.h

templateFromContentsOfURL:error:

Parses a template file, and returns a compiled template.

+ (instancetype)templateFromContentsOfURL:(NSURL *)url error:(NSError **)error

Parameters

url

The URL of the template.

error

If there is an error loading or parsing template and

             partials, upon return contains an NSError object that
             describes the problem.

Return Value

A GRMustacheTemplate instance.

Availability

Discussion

The template at url must be encoded in UTF8. See the GRMustacheTemplateRepository class for more encoding options.

Declared In

GRMustacheTemplate.h

templateFromResource:bundle:error:

Parses a bundle resource template, and returns a compiled template.

+ (instancetype)templateFromResource:(NSString *)name bundle:(NSBundle *)bundle error:(NSError **)error

Parameters

name

The name of a bundle resource of extension “mustache”.

bundle

The bundle where to look for the template resource. If nil,

             the main bundle is used.
error

If there is an error loading or parsing template and

             partials, upon return contains an NSError object that
             describes the problem.

Return Value

A GRMustacheTemplate instance.

Availability

Discussion

If you provide nil as a bundle, the resource will be looked in the main bundle.

The template resource must be encoded in UTF8. See the GRMustacheTemplateRepository class for more encoding options.

Declared In

GRMustacheTemplate.h

templateFromString:error:

Parses a template string, and returns a compiled template.

+ (instancetype)templateFromString:(NSString *)templateString error:(NSError **)error

Parameters

templateString

The template string.

error

If there is an error loading or parsing template and

                   partials, upon return contains an NSError object that
                   describes the problem.

Return Value

A GRMustacheTemplate instance.

Availability

Declared In

GRMustacheTemplate.h

Instance Methods

renderContentWithContext:HTMLSafe:error:

Returns the rendering of the receiver, given a rendering context.

- (NSString *)renderContentWithContext:(GRMustacheContext *)context HTMLSafe:(BOOL *)HTMLSafe error:(NSError **)error

Parameters

context

A rendering context.

HTMLSafe

Upon return contains YES or NO, depending on the content

             type of the template, as set by the configuration of the
             source template repository. HTML templates yield YES, text
             templates yield NO.
error

If there is an error rendering the tag, upon return contains

             an NSError object that describes the problem.

Return Value

The rendering of the template.

Availability

Declared In

GRMustacheTemplate.h

renderObject:error:

Renders a template with a context stack initialized with the provided object on top of the base context.

- (NSString *)renderObject:(id)object error:(NSError **)error

Parameters

object

An object used for interpreting Mustache tags.

error

If there is an error rendering the template and its

           partials, upon return contains an NSError object that
           describes the problem.

Return Value

A string containing the rendered template.

Availability

Declared In

GRMustacheTemplate.h

renderObjectsFromArray:error:

Renders a template with a context stack initialized with the provided objects on top of the base context.

- (NSString *)renderObjectsFromArray:(NSArray *)objects error:(NSError **)error

Parameters

objects

An array of context objects for interpreting Mustache tags.

error

If there is an error rendering the template and its

            partials, upon return contains an NSError object that
            describes the problem.

Return Value

A string containing the rendered template.

Availability

Declared In

GRMustacheTemplate.h