Skip to content

Conformance Examples 0.1.0 — Partials: basic-rendering

partial-renders-against-current-context

A partial renders against the current context, so an identifier inside it resolves against the active scope.

Template

Hello, {{> who }}!

Context

{
    "name": "Alice"
}

Partials

who:

{{ name }}

Output

Hello, Alice!

partial-inside-each-sees-loop-element

A partial used inside {{#each}} renders against the element the loop pushed onto the context stack.

Template

{{#each member }}- {{> memberInfo }}
{{/each}}

Context

{
    "member": [
        {
            "name": "Alice"
        },
        {
            "name": "Bob"
        }
    ]
}

Partials

memberInfo:

{{ name }}

Output

- Alice
- Bob

dynamic-key-resolves-partial-from-context

A dynamic {{> (expr) }} key is evaluated against the context and used to resolve the partial.

Template

{{> (which) }}

Context

{
    "which": "greeting",
    "name": "Alice"
}

Partials

greeting:

Hi {{ name }}

Output

Hi Alice

dynamic-key-with-inner-whitespace-resolves-identically

Whitespace immediately inside a dynamic partial key's parentheses is optional: '{{> ( which ) }}' renders identically to '{{> (which) }}' above.

Template

{{> ( which ) }}

Context

{
    "which": "greeting",
    "name": "Alice"
}

Partials

greeting:

Hi {{ name }}

Output

Hi Alice

Source fixture: partials/basic-rendering.json