pystache
pystache copied to clipboard
Adding the ability to select list items in the context by index.
This matches the behavior of JS implementations of mustache. Tested against mustache.js and Hogan.
>>> context = {"data": ['one', 'two', 'three']}
>>> pystache.render("{{ data.0 }}", context)
'one'
Tests added and all previous behavior maintained.
Is this a duplicate of issue #134?
@cjerdonek I haven't actually tried the syntax in #134, but I'd imagine that this solves that as well.
I think checkin 316c9d4 to support element cherrypick by index with syntax "{{array_key.index}}" is very important feature for this project.
Without this feature, some data could not be rendered from array.
If you try http://mustache.github.io/#demo, you could find that javascript library has already supported this syntax.
This has not been added yet?
:+1:
Very important and interesting feature indeed!
I would like to have this functionality as well.
Hi @cjerdonek can this be merged please?
I too would love to have this merged in. Any chance that this project will be updated ever again?
Any reason why this hasn't been merged?
@cjerdonek is this repo (and this useful PR that it contains) no longer being maintained?
I would like this feature as well.
but also would be nice to access the last element as a function
>>> context = {"data": ['one', 'two', 'three']}
>>> pystache.render("{{ data.first() }}", context)
'one'
>>> pystache.render("{{ data.last() }}", context)
'three'