Skip to content

Selector for index in an array: items.0.name #64

@mattslocum

Description

@mattslocum

In other implementations of mustache there is the ability to write a selector into an array by the index. Ex: items.0.name. This doesn't seem possible with the golang implementation. I understand how it is potentially free in JS, but it would require extra effort in golang. Is this something that could be supported in the future?

Similar requests by other libraries (with mixed results):
Python: defunkt/pystache#196
C#: DanieleScipioni/Mustache#2
Erlang: soranoba/bbmustache#41
Swift: groue/GRMustache.swift#2

Alternative idea: Methods that support params.
golang's text/template supports index lookup with functions.

{{ (index .items 0).Name }}

try it: https://play.golang.org/p/dgIMARysMOX

It looks like this library already supports functions on the struct, but it didn't seem to support params. If it did, then a getter could be added as needed.

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