Skip to content

Conformance Examples 0.1.0 — Render: each-index-key

at-foo-literal-property-via-dot-slash

{{ ./@foo }} reads a literal '@foo' property via RFC 6901 Pointer in the root context.

Template

{{ ./@foo }}

Context

{
    "@foo": "bar"
}

Output

bar

at-foo-literal-property-via-this-dot

{{ this.@foo }} reads a literal '@foo' property via dot-notation Pointer in the root context.

Template

{{ this.@foo }}

Context

{
    "@foo": "bar"
}

Output

bar

at-foo-literal-property-via-this-slash

{{ this/@foo }} reads a literal '@foo' property via RFC 6901 Pointer in the root context.

Template

{{ this/@foo }}

Context

{
    "@foo": "bar"
}

Output

bar

at-index-outside-each-is-null

@index outside any {{#each}} block resolves to null.

Template

{{ @index }}

Context

{}

Output

null

at-key-html-escaped

@key inside an object each is HTML-escaped when rendered with {{ }} interpolation.

Template

{{#each m }}{{ @key }};{{/each}}

Context

{
    "m": {
        "<a>": 1
    }
}

Output

&lt;a&gt;;

at-key-outside-each-is-null

@key outside any {{#each}} block resolves to null.

Template

{{ @key }}

Context

{}

Output

null

at-key-unescaped-triple-mustache

@key inside an object each is emitted verbatim (unescaped) when rendered with {{{ }}} interpolation.

Template

{{#each m }}{{{ @key }}};{{/each}}

Context

{
    "m": {
        "<a>": 1
    }
}

Output

<a>;

at-unknown-is-null

An unrecognised @name identifier (forward-compat) renders as null.

Template

{{#each items }}{{ @bogus }};{{/each}}

Context

{
    "items": [
        1,
        2
    ]
}

Output

null;null;

each-index-array-zero-based

@index inside an array {{#each}} renders the 0-based element index.

Template

{{#each items }}{{ @index }}-{{ this }};{{/each}}

Context

{
    "items": [
        10,
        20,
        30
    ]
}

Output

0-10;1-20;2-30;

each-index-inside-object-is-null

@index inside an object {{#each}} is null because objects iterate by key, not index.

Template

{{#each scores }}{{ @index }};{{/each}}

Context

{
    "scores": {
        "a": 1
    }
}

Output

null;

each-key-inside-array-is-null

@key inside an array {{#each}} is null because arrays iterate by index, not key.

Template

{{#each items }}{{ @key }};{{/each}}

Context

{
    "items": [
        1
    ]
}

Output

null;

each-key-object-insertion-order

@key inside an object {{#each}} renders each key; keys are iterated in insertion order.

Template

{{#each scores }}{{ @key }}={{ this }};{{/each}}

Context

{
    "scores": {
        "c": 3,
        "a": 1,
        "b": 2
    }
}

Output

c=3;a=1;b=2;

each-parent-index-from-nested-each

{{ ../@index }} inside a nested {{#each}} reaches the outer each's @index.

Template

{{#each outer }}{{#each inner }}{{ ../@index }}.{{ @index }};{{/each}}{{/each}}

Context

{
    "outer": [
        {
            "inner": [
                "a",
                "b"
            ]
        },
        {
            "inner": [
                "c"
            ]
        }
    ]
}

Output

0.0;0.1;1.0;

each-parent-key-from-nested-each

{{ ../@key }} inside a nested {{#each}} over an array reaches the outer each's @key (if the outer is an object each).

Template

{{#each groups }}{{#each this }}{{ ../@key }}/{{ this }};{{/each}}{{/each}}

Context

{
    "groups": {
        "x": [
            "a",
            "b"
        ],
        "y": [
            "c"
        ]
    }
}

Output

x/a;x/b;y/c;

Source fixture: render/each-index-key.json