Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
85 lines (62 sloc) 2.68 KB

up, next

Partial templates

When a {{>name}} Mustache tag occurs in a template, GRMustache renders in place the content of another template, the partial, identified by its name.

You can write recursive partials. Just avoid infinite loops in your context objects.

Source of partials

Depending on the method which has been used to create the original template, partials will be searched in different places :

  • In the main bundle, with ".mustache" extension:
    • renderObject:fromString:error:
    • templateFromString:error:
  • In the specified bundle, with ".mustache" extension:
    • renderObject:fromResource:bundle:error:
    • templateFromResource:bundle:error:
  • In the specified bundle, with the provided extension:
    • renderObject:fromResource:withExtension:bundle:error:
    • templateFromResource:withExtension:bundle:error:
  • Relatively to the URL of the including template, with the same extension:
    • renderObject:fromContentsOfURL:error:
    • templateFromContentsOfURL:error:
  • Relatively to the path of the including template, with the same extension:
    • renderObject:fromContentsOfFile:error:
    • templateFromContentsOfFile:error:

Check Guides/ for more partial loading strategies.

Overriding portions of partials

Partials may contain overridable sections. Those sections start with a dollar instead of a pound. For example, let's consider the following partial:

    <title>{{$page_title}}Default title{{/page_title}}</title>
    <h1>{{$page_title}}Default title{{/page_title}}</h1>
        Default content

You can embed such an overridable partial, and override its sections with the {{<partial}}...{{/partial}} syntax:


    {{! override page_title }}

    {{! override page_content }}
            by {{author}}


When you render article.mustache, you will get a full HTML page.

You can override a section with attached data, as well:

        by anonymous coward

up, next

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