Skip to content
This repository was archived by the owner on Oct 6, 2023. It is now read-only.
This repository was archived by the owner on Oct 6, 2023. It is now read-only.

Direct addressing of specific array elements #29

@davemerrill

Description

@davemerrill

This works fine, iterating over the elements in an array:

data = {arr=[10,20,30]};
template = "{{##arr}}{{.}}{{/arr}}";
writeOutput(mustache.render(template, data));

How can you show just element 2, say? Not with any of these seemingly intuitive constructs:

template = "{{arr.2}}";
template = "{{arr[2]}}";

My actual use case is more like this:

data = {arr=[{a=10, b=11}, {a=20, b=21}]};
template = "{{arr.2.b}}"; // or whatever would work to output '21'

The similar case of addressing a specific struct item does work, for instance:

data = {s={a=10, b=20, c=30}};
template = "({{s.b}})"; // -> '20'

Is the array element index version of this possible today with some syntax I missed?
If not, is it a reasonable enhancement?

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions